#includeint main(int argc, char *argv[]) { QApplication app(argc, argv); QImage originalImage("image.jpg"); QImage copiedImage = originalImage.copy(); // create a copy of the original image // display the copied image QLabel label; label.setPixmap(QPixmap::fromImage(copiedImage)); label.show(); return app.exec(); }
#includeIn this example, we create a copy of the originalImage and modify it using QPainter. We draw some text onto the copied image and display it in a QLabel widget using QPixmap. The QImage and QPixmap classes are part of the QtWidgets package in the Qt library.int main(int argc, char *argv[]) { QApplication app(argc, argv); QImage originalImage("image.jpg"); QImage copiedImage = originalImage.copy(); // create a copy of the original image // modify the copied image QPainter painter(&copiedImage); painter.setPen(Qt::red); painter.drawText(copiedImage.rect(), Qt::AlignCenter, "Hello, world!"); // display the modified image QLabel label; label.setPixmap(QPixmap::fromImage(copiedImage)); label.show(); return app.exec(); }