0

我正在使用 imagemagick DLL(请参阅:http ://www.imagemagick.org )来调整图像大小,
但是当我重新调整动画 GIF 图像的大小时,它就搞砸了。

我使用以下代码重新调整图像大小(图像类型为 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);

我该如何修复它。查看结果图像在此处输入图像描述

4

1 回答 1

3

我认为您必须首先从 gif 中提取每一帧,调整每一帧的大小,然后将其重新组合在一起。

编辑:像这样?未测试也未构建...

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);    
于 2011-02-08T12:02:06.010 回答