Hi,
I want to create an animated gif from some in memory data. I am trying to implement this in a VC++ 2005.
I am able to compile the solution provided with the IM Windows release and execute the IMDisplay utility for reading image files.
I have prepared a test solution in which I wrote similar code as the IMDisplay utility to read image files. This is working fine.
Now I want to write data into multiple frames in memory and then write those frames to a single animated gif file. I am not sure of how to go about this.
Most of the documentation is related to the command line utilities. I went through the documentation for Magick++ briefly. I am aware that I can write to gif file by using Image::write(filename). However this creates a non-animated gif file. I could not find any API which helps create an animated GIF file with multiple frames.
Can someone point me out the appropriate Magick++ API which I should use to create an animated gif file?
I went through the documentation for MagickCore too and there a few APIs, viz. NewImageList, AppendImageToList. Are these what I should use for my problem? It would help if someone could point me to some sample code available. I would prefer to use the Magick++ api, though.
thanks in advance,
Abhi
Creating animated GIFs using Magick++/MagickCore APIs
Re: Creating animated GIFs using Magick++/MagickCore APIs
Got it, following code worked for me:
Image img1( "100x100", "white" );
img1.pixelColor( 49, 49, "red" );
frames.push_back(img1);
Image img2( "100x100", "red" );
img2.pixelColor( 49, 49, "white" );
frames.push_back(img2);
img1.animationDelay(2000);
img2.animationDelay(2000);*/
Magick::writeImages(frames.begin(), frames.end(), "f:\\2.gif");
Image img1( "100x100", "white" );
img1.pixelColor( 49, 49, "red" );
frames.push_back(img1);
Image img2( "100x100", "red" );
img2.pixelColor( 49, 49, "white" );
frames.push_back(img2);
img1.animationDelay(2000);
img2.animationDelay(2000);*/
Magick::writeImages(frames.begin(), frames.end(), "f:\\2.gif");
-
- Posts: 36
- Joined: 2010-02-21T18:02:40-07:00
- Authentication code: 8675308
Re: Creating animated GIFs using Magick++/MagickCore APIs
Thanks. Took me a while to find this by searching.
If you are trying to write multi-page TIFF files, just do this:
If you are trying to write multi-page TIFF files, just do this:
Code: Select all
vector<Magick::Image> frames;
Magick::Image img1("D:/img.bmp"), img2 ("D:/leaves.jpg");
img1.compressType(MagickLib::JPEGCompression); img1.quality(20); //set JPEG compression at 20%
img2.compressType(MagickLib::JPEGCompression); img2.quality(20); //set JPEG compression at 20%
//add the images into the STL container
frames.push_back(img1); frames.push_back(img2);
Magick::writeImages(frames.begin(), frames.end(), "D:/multi.tif");