#include#include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QImage image("image.png"); QLabel label; label.setPixmap(QPixmap::fromImage(image)); label.show(); return app.exec(); }
QImage image("image.png"); for (int y = 0; y < image.height(); ++y) { QRgb *row = reinterpret_castThis code loads an image from a file "image.png" and modifies its data to convert it to grayscale. It uses QImage::scanLine() to get a pointer to the raw pixel data of each row, then accesses each pixel using QRgb. Package Library: Qt (QtCore and QtGui)(image.scanLine(y)); for (int x = 0; x < image.width(); ++x) { QRgb color = row[x]; int gray = qGray(color); row[x] = qRgb(gray, gray, gray); } }