문제

I have next code for resizing images:

Image image;
image.read( imagePath.toStdString() );
Geometry newSize = Geometry(m_newSize.width(), m_newSize.height());
newSize.aspect(true);
image.resize(newSize);
image.write(newImagePath.toStdString());

This code work fine for non-gif files. For gif files I loss animation: Before resizing gif file

After resizng

How to resize gif files without animation loss?

도움이 되었습니까?

해결책

I found a solution! Thank you MofX for right direction!

   Geometry newSize = Geometry(m_newSize.width(), m_newSize.height());
   newSize.aspect(true); 
   list<Image> frames;
   readImages(&frames, imagePath.toStdString());
   for (auto& image : frames)
        image.resize(newSize);
   writeImages(frames.begin(), frames.end(), newImagePath.toStdString());

다른 팁

You have to use readImages and animateImages to read all frames of the animation into an image list and to add them to an animation.

Look at this example at http://www.imagemagick.org/Magick++/STL.html:

#include <list> 
#include <Magick++.h> 
using namespace std; 
using namespace Magick;

int main(int /*argc*/,char **/*argv*/) 
{ 
    list<Image> imageList; 
    readImages( &imageList, "test_image_anim.gif" );

    Image appended; 
    appendImages( &appended, imageList.begin(), imageList.end() ); 
    appended.write( "appended_image.miff" ); 
    return 0; 
}

The only problem is, that the documentation says, that animatImages works only under X11

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top