Quantcast
Channel: magick Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 1011

Commented Unassigned: Animated gif generating [1378]

$
0
0
I can't really understand, why gif animation isn't working without this?
```
//Optionally reduce colors
QuantizeSettings settings = new QuantizeSettings { Colors = 256 };
collection.Quantize(settings);

// Optionally optimize the images (images should have the same size).
collection.Optimize();
```
2 png frames, same size. Without code above it creates gif with only 1 frame. With code above, everything is fine. Is it a bug of reature?
Comments: Sorry, it's not that simple. I'm generating those images on the fly from XAML frames and I'm doing it in memory without saving anything directly into files. And yes, I'm setting animation delay for each frame. This is my code, which can be helpful. ``` byte[] bytes; using (var collection = new MagickImageCollection()) { foreach (var frame in stateWithPic.Frames) { var frame1 = frame; frame1.Image = frame1.Image.Replace("#000000", "#FF0F0F0F"); Canvas surface; var imageBytes = Encoding.Unicode.GetBytes(frame1.Image ?? ""); using (var stream = new MemoryStream(imageBytes)) { surface = (Canvas)XamlServices.Load(stream); } var pngBitmap = surface != null ? InternalConverter.XamlCanvasToPngBitmap(surface) : null; if (pngBitmap == null) { continue; } var img = new MagickImage(pngBitmap) { AnimationDelay = frame.Duration / 10, HasAlpha = true }; collection.Add(img); } if (collection.Count == 0) { return string.Empty; } //Optionally reduce colors QuantizeSettings settings = new QuantizeSettings { Colors = 256 }; collection.Quantize(settings); // Optionally optimize the images (images should have the same size). collection.Optimize(); using (var str = new MemoryStream()) { collection.Write(str, MagickFormat.Gif); bytes = str.ToArray(); } } ``` So, without ``` //Optionally reduce colors QuantizeSettings settings = new QuantizeSettings { Colors = 256 }; collection.Quantize(settings); // Optionally optimize the images (images should have the same size). collection.Optimize(); ``` it's not working properly. But with this code everything works fine so far.

Viewing all articles
Browse latest Browse all 1011

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>