+ 3
How to add image in cpp...?
I need to know how can we add images to cpp codes ...help...and please elaborate
8 Answers
+ 9
You have to use external libraries for that.
For instance,
http://www.imagemagick.org/Magick++/
https://www.qt.io
+ 4
ok
+ 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;
}
+ 3
Thanks for the help julien.đâșïž
+ 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; }
+ 2
julien can you please show an example I didn't understood the explanation well...
+ 2
would that work in sololearn too....?