Opening and Displaying an Image in C++?

In c++ (without any extra library) you may open an image. But there will be nothing particularly useful except a bunch of binary data. then you have to use your own decoder If you use opencv you can write to open an image and display it:

Mat m("fileName");
imshow("windowName",m);

To do the same with a general purpose library like qt you can use this code :

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QGraphicsScene scene;
    QGraphicsView view(&scene);
    QGraphicsPixmapItem item(QPixmap("c:\\test.png"));
    scene.addItem(&item);
    view.show();
    return a.exec();
}

To learn more about imageviewer widget go here. Or you may have a look at here to display as graphics view.


For a crossplatform, opensource and very good library you can use libmagick++.

Tags:

C++

Image

Sample