我正在使用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);
我该如何修理它? 查看结果图像
答案 0 :(得分: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);