Hello,
Can't resize an animated GIF when using streams instead of directory paths... The stream has 0 length... Could you help me with this?
Code snippet:
I'm using Graphics Mill v9.0.21
Thank you,
Bruno
attach #1307
Can't resize an animated GIF when using streams instead of directory paths... The stream has 0 length... Could you help me with this?
Code snippet:
private static byte[] ResizeAnimatedGif(byte[] media, int Width, int height)
{
using (var exportedImageStream = new MemoryStream())
using (var imageReader = new GifReader(new MemoryStream(media)))
using (var imageWriter = new GifWriter(exportedImageStream))
{
var kX = (float)Width / (float)imageReader.Width;
var kY = (float)height / (float)imageReader.Height;
imageWriter.BackgroundIndex = imageReader.BackgroundEntryIndex;
imageWriter.Palette = imageReader.Palette;
imageWriter.PlaybackCount = imageReader.PlaybackCount;
for (var i = 0; i < imageReader.Frames.Count; i++)
{
using (var frame = imageReader.Frames[i])
using (var bitmap = frame.GetBitmap())
{
var palette = bitmap.Palette;
var pixelFormat = bitmap.PixelFormat;
// Convert the bitmap to a non-indexed format
bitmap.ColorManagement.Convert(ColorSpace.Rgb, true, false);
var newWidth = Math.Max(1, (int)(bitmap.Width * kX));
var newHeight = Math.Max(1, (int)(bitmap.Height * kY));
//Use ResizeInterpolationMode.Low to prevent noise
bitmap.Transforms.Resize(newWidth, newHeight, ResizeInterpolationMode.Low);
bitmap.Palette = palette;
bitmap.ColorManagement.Convert(pixelFormat);
imageWriter.FrameOptions.Left = (ushort)(frame.Left * kX);
imageWriter.FrameOptions.Top = (ushort)(frame.Top * kY);
imageWriter.FrameOptions.Delay = frame.Delay;
imageWriter.FrameOptions.DisposalMethod = frame.DisposalMethod;
Pipeline.Run(bitmap + imageWriter);
}
}
return exportedImageStream.GetBuffer();
}
}
I'm using Graphics Mill v9.0.21
Thank you,
Bruno
attach #1307