Magick.NET
Magick.NET copied to clipboard
Gif frame image size read wrong
Magick.NET version
13.5.0
Environment (Operating system, version and so on)
windows 11 x64
Description
only first frame is correct when read image's size.
2023-12-29 04:38:35 192 width:160 height:80 2023-12-29 04:38:35 209 width:50 height:50 2023-12-29 04:38:35 212 width:10 height:10 2023-12-29 04:38:35 213 width:50 height:40 2023-12-29 04:38:35 216 width:10 height:10 2023-12-29 04:38:35 218 width:1 height:1 2023-12-29 04:38:35 219 width:1 height:1 2023-12-29 04:38:35 221 width:45 height:30 2023-12-29 04:38:35 223 width:40 height:25 2023-12-29 04:38:35 225 width:50 height:30 2023-12-29 04:38:35 228 width:5 height:5 2023-12-29 04:38:35 229 width:55 height:49 2023-12-29 04:38:35 231 width:25 height:44 2023-12-29 04:38:35 233 width:55 height:44 2023-12-29 04:38:35 235 width:55 height:29 2023-12-29 04:38:35 238 width:45 height:29 2023-12-29 04:38:35 240 width:45 height:24 2023-12-29 04:38:35 242 width:1 height:1
then if i using Montage function to merge a black layer.
I will got a wrong gif. correct gif should be same as original one.
Steps to Reproduce
using var images = new MagickImageCollection();
using (var oriImages = new MagickImageCollection(openFilePath))
{
foreach (var item in oriImages)
{
Console.WriteLine($@"width:{item.Width} height:{item.Height}");
var image = MergeLayer(item, 160, 80);
images.Add(image);
}
}
images.Write(newFileName);
private static IMagickImage<ushort> MergeLayer(IMagickImage<ushort> second, int width, int height)
{
using var images = new MagickImageCollection();
images.Add(second);
var result = images.Montage(
new MontageSettings()
{
Gravity = Gravity.Center,
Geometry = new MagickGeometry(0, 0, width, height),
BackgroundColor = new MagickColor(0, 0, 0, 0),
});
return result;
}
Those images don't have the wrong size. One thing that you are not printing is the x
and y
position of the Page
property of the image. And the GifDisposeMethod
property of that image determines how the image is drawn. It is a bit unclear what you are trying to accomplish but if you are trying to get the frames of the gif image as they are drawn per frame you probably want to use the Coalesce()
method of the IMagickImageCollection
.