The original "big.jpg" is 480×3200, it contains 5 frames or regions I'm interested in. After extracting/cropping the image(s) they are pushed into a vector. The vector is then used to write a gif using Magick::writeImages. The problem is that I'm ending up with a gif that is the same width/height i.e. "480×3200" which animates each extracted frame downwards. The result I was expecting was a 480x640 gif.
Code: Select all
Magick::Image originalImage ("big.jpg");
Magick::Geometry originalGeometry = originalImage.size();
vector<Magick::Image> frames;
const int frameHeight = 640;
for (int i = 0; i < originalGeometry.height(); i += frameHeight) {
Magick::Geometry geometry = Magick::Geometry (originalGeometry.width(), frameHeight, 0, i);
Magick::Image image = originalImage;
if ((int) (originalGeometry.width() - geometry.xOff()) < 1 || (int) (originalGeometry.height() - geometry.yOff()) < 1) {
continue;
}
image.crop (geometry);
frames.push_back (image);
}
Magick::writeImages (frames.begin(), frames.end(), "final.gif");
One thing I tried that does work but feels wrong is doing another pass through all the frames, write out each image to a Blob, read it back into an Image and add it to a new "finalFrames" vector. This obviously increases memory usage.
Code: Select all
vector<Magick::Image> finalFrames;
for (vector <Magick::Image>::iterator it = frames.begin(); it != frames.end(); ++it) {
Magick::Image image = *it;
Magick::Blob blob;
image.write (&blob);
Magick::Image newImage (blob);
finalFrames.push_back (newImage);
}
Magick::writeImages (finalFrames.begin(), finalFrames.end(), "final.gif");
Thank You in Advance.