Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening and Displaying an Image in C++?

Tags:

c++

image

sample

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!

like image 501
awhipp Avatar asked Nov 23 '13 22:11

awhipp


2 Answers

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.

like image 184
deeiip Avatar answered Oct 21 '22 04:10

deeiip


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

like image 20
peterh Avatar answered Oct 21 '22 04:10

peterh