-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
The demo use a static image, create multiple frame by rotation and save a gif. But if the original Image loaded is a Gif, it seems to create a corrupted file.
See this code:
private static byte[] ToGifByteArray(Image image)
{
var frameCount = image.GetFrameCount(FrameDimension.Time);
var times = image.GetPropertyItem(0x5100).Value; // PropertyTagFrameDelay
using (var memoryStream = new MemoryStream())
{
using (var encoder = new GifEncoder(memoryStream, null, null, -1))
{
for (var idx = 0; idx < frameCount; idx++)
{
image.SelectActiveFrame(FrameDimension.Time, idx);
var dur = BitConverter.ToInt32(times, 4 * 0);
encoder.AddFrame(image, 0, 0, TimeSpan.FromSeconds(dur));
}
}
File.WriteAllBytes(@"C:\test.gif", memoryStream.ToArray());
return memoryStream.ToArray();
}
}
If I pass a Image loaded from a gif, it create a corrupted. If I comment the first two lines for the timing and the loop for the frame and pass a Image loaded from a jpeg, it create a working gif.
Metadata
Metadata
Assignees
Labels
No labels