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!
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!
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++.
modified Hello World sample from OpenCV 2 Computer Vision Application Programming Cookbook running in VS 2012 win32 Console app
or official OpenCV (Open Source) sample
warning: opencv-2.4.10.exe Win installer is 360 MB which have many advance features and have sample code, Doc and built binaries in Python and Java too x86 and 64 in it too
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main()
{
// read an image
cv::Mat image= cv::imread("img.jpg");
// create image window named "My Image"
cv::namedWindow("My Image");
// show the image on window
cv::imshow("My Image", image);
// wait key for 5000 ms
cv::waitKey(5000);
return 0;
}