简体   繁体   English

如何在不破坏C#动画的情况下使用imagemagick调整动画gif文件的大小?

[英]How to resize animated gif file using imagemagick without destroying animation using C#?

I am using imagemagick DLL (Refer: http://www.imagemagick.org ) for the resize image, 我正在使用imagemagick DLL(请参阅: http : //www.imagemagick.org )来调整图像大小,
But when I re-sized animated GIF image then it going screw. 但是,当我重新调整动画GIF图像的大小时,它就会发生问题。

I using below code for re-size image ( image type are png, gif, jpg, bmp, tif ...) 我使用以下代码调整图像大小(图像类型为png,gif,jpg,bmp,tif ...)

ImageMagickObject.MagickImage imgLarge = new ImageMagickObject.MagickImage();
 object[] o = new object[] { strOrig, "-resize", size, "-gravity", "center", "-colorspace", "RGB", "-extent", "1024x768", strDestNw };
imgLarge.Convert(ref o);

How can I fixed it. 我该如何解决。 see the result image 查看结果图片 在此处输入图片说明

I think you have to extract every single frame from the gif first, resize every single frame and then put it back together. 我认为您必须首先从gif中提取每个帧,调整每个帧的大小,然后再放回去。

Edit: like this? 编辑:这样吗? Not tested nor builded... 未经测试或构建...

int maxFrames=32;
ImageMagickObject.MagickImage imgLarge = new ImageMagickObject.MagickImage();  

// first extract all frames from gif to single png files
for(int frame=0; frame<maxFrames;frame++)
{
   object[] o = new object[] { String.Format(strOrig+"[{0}]", frame)
       ,  String.Format("tmp{0}.png", frame) };
   imgLarge.Convert(ref o);    
}
// resize every single png files
// add resized filenames to stringbuilder
StringBuilder filenames = new StringBuilder();
for(int frame=0; frame<maxFrames;frame++)
{
   object[] o = new object[] { String.Format("tmp{0}.png", frame)
                , "-resize"
                , size 
                , "-gravity"
                , "center"
                , "-colorspace"
                , "RGB"
                , "-extent"
                , "1024x768"
                , String.Format("tmp-resized{0}.png", frame) };
   filenames.Append(String.Format("tmp-resized{0}.png", frame));
   filenames.Append(Environment.NewLine);
   imgLarge.Convert(ref o);    
}
// write resized filenames to file
File.WriteAllText("tmp-resized-files.txt", filenames);
// create resize animated gif based on filenames in the tmp-resized-files.txt
   object[] o = new object[] { "@tmp-resized-files.txt"
       ,  strDestNw };
   imgLarge.Convert(ref o);    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM