Opening and Displaying an Image in C++?

c++, image, sample

Solution

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.

Problem

Basically I am teaching myself C++ and part of the program function will be to open and close an image specified. How would I go about doing this? Or what resource would I use? Thanks!

Original source

Related problems