我正在尝试制作一个将彩色图像转换为黑白图像的简单程序。
到目前为止,我已经做到了。
void ObradaSlike::convert_picture_to_bw()
{
QImage image;
image.load(fileModel->fileInfo(listView->currentIndex()).absoluteFilePath());
QSize sizeImage = image.size();
int width = sizeImage.width(), height = sizeImage.height();
QRgb color;
int value;
for (int f1=0; f1<width; f1++) {
for (int f2=0; f2<height; f2++) {
color = image.pixel(f1, f2);
image.setPixel(f1, f2, QColor((qRed(color) + qGreen(color) + qBlue(color))/3).rgb());
}
}
sceneGraphics->clear();
sceneGraphics->addPixmap(QPixmap::fromImage(image));
}
我认为代码应该可以工作,但是有一个问题。
这段代码的问题是我总是得到蓝黑色图像和黑白图像。你知道如何解决这个问题。
谢谢。