How to add image in cpp...? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to add image in cpp...?

I need to know how can we add images to cpp codes ...help...and please elaborate

18th Mar 2018, 11:36 AM
Madhav
Madhav - avatar
7 Answers
+ 9
You have to use external libraries for that. For instance, http://www.imagemagick.org/Magick++/ https://www.qt.io
18th Mar 2018, 11:57 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
ok
18th Mar 2018, 11:56 AM
TrueJu
TrueJu - avatar
+ 4
I found something that is easier than mine: #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main( int argc, char** argv ) { if( argc != 2) { cout <<" Usage: display_image ImageToLoadAndDisplay" << endl; return -1; } Mat image; image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file if(! image.data ) // Check for invalid input { cout << "Could not open or find the image" << std::endl ; return -1; } namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display. imshow( "Display window", image ); // Show our image inside it. waitKey(0); // Wait for a keystroke in the window return 0; }
18th Mar 2018, 12:01 PM
TrueJu
TrueJu - avatar
+ 3
Thanks for the help julien.😊☺️
18th Mar 2018, 12:08 PM
Madhav
Madhav - avatar
+ 2
#include <Magick++.h> #include <iostream> using namespace std; using namespace Magick; int main(int argc,char **argv) { // Construct the image object. Seperating image construction from the // the read operation ensures that a failure to read the image file // doesn't render the image object useless. Image image; try { // Read a file into image object image.read( "girl.jpeg" ); // Crop the image to specified size (width, height, xOffset, yOffset) image.crop( Geometry(100,100, 100, 100) ); // Write the image to a file image.write( "x.jpeg" ); } catch( Exception &error_ ) { cout << "Caught exception: " << error_.what() << endl; return 1; } return 0; }
18th Mar 2018, 11:53 AM
TrueJu
TrueJu - avatar
+ 2
julien can you please show an example I didn't understood the explanation well...
18th Mar 2018, 11:55 AM
Madhav
Madhav - avatar
+ 2
would that work in sololearn too....?
18th Mar 2018, 11:58 AM
Madhav
Madhav - avatar