tags:

views:

122

answers:

4

Can you create a PNG, GIF, etc with C++ on windows?

If it's possible, how? For an example how can you make a png image just one solid color.

Just a "hello world" example would be great...

+1  A: 

For PNG, try out the PNGWriter library: http://pngwriter.sourceforge.net/

kbrimington
+1  A: 

Yes, it is possible to do so. Some libraries for image manipulation include ImageMagick/GraphicsMagick (same API), CImg, and OpenCV. OpenCV is by far the most powerful but also the most difficult to use. CImg is probably the easiest to use, and I would strongly recommend it for beginners... you basically create an instance of the CImg<pixel_type> type, fill in the pixels, and then call "save", which will automatically deduce the type and knows how to encode it based on the file extension you give it.

Michael Aaron Safyan
+1  A: 

Images are just binary files and C++ can easily write binary files. Image formats include many complicated compression algorithms so doing so is not always easy.

Its generally best to use a C++ library which can handle the loading/saving of such files for you so you can worry about more important things like you'd actually like these pictures to have in them.

Imaghttp://www.imagemagick.org is a popular one used by several open source projects but there are many others.

MerickOWA
+3  A: 

When someone asks you about Hello world, just say Hello world ...

#include "opencv/cxcore.h"
#include "opencv/cv.h"
#include "opencv/highgui.h"

int _tmain(int argc, _TCHAR* argv[])
{
    cv::Mat image(480, 640, CV_8UC3);
    cv::putText(image, "Hello world", cvPoint(320, 200), 
        CV_FONT_HERSHEY_SIMPLEX, 1, cvScalar(255, 0, 0));
    cv::imwrite("output.tif", image);
    return 0;
}
rwong