16,211
社区成员
发帖
与我相关
我的任务
分享
QString fileName = QFileDialog::getOpenFileName(this, "打开文件", "", "");
if (fileName.isEmpty())
return;
QImage image(fileName);
int chaos;
double a;
double x;
double keys[][2] = {{4, 0.6}, {3.999, 0.8}, {3.7, 0.7}, {3.888, 0.6}};
for (int kNum = 0; kNum < 4; ++kNum)
{
a = keys[kNum][0];
x = keys[kNum][1];
for (int c = 0; c < 1000; ++c)
x = a*x*(1-x);
for (int j = 0; j < image.height(); ++j)
{
for (int i = 0; i < image.width(); ++i)
{
chaos = 0;
for (int c = 0; c < 8; ++c)
{
x = a*x*(1-x);
if (x >= a/6)
chaos = ((chaos << 1) | 1);
else
chaos = ((chaos << 1) | 0);
}
QColor color(image.pixel(i, j));
color.setRed(color.red() ^ chaos);
color.setGreen(color.green() ^ chaos);
color.setBlue(color.blue() ^ chaos);
image.setPixel(i, j, color.rgb());
}
}
}
QString saveName = QFileDialog::getSaveFileName(this, "保存文件", "", "");
if (saveName.isEmpty())
return;
image.save(saveName, fileName.section('.', -1).toStdString().c_str(), 100);