Here is my simple function
```
public byte[] CreateWithImageMagic(Bitmap[] images) {
try {
using (var collection = new MagickImageCollection()) {
foreach (Bitmap t in images) {
var imageMagicItem = new MagickImage(t) { AnimationDelay = 100 };
collection.Add(imageMagicItem);
}
collection.Optimize();
using (var stream = new MemoryStream()) {
collection.ToByteArray(); // This call kills the app
collection.Write(stream); // This call kills the app
collection.ForEach(i => i.Dispose());
return stream.ToArray();
}
}
}
catch (Exception ex) {
throw ex;
}
}
```
If I use the `Write(String)` overload (path on disc) the code executes successfully and the animated gif is created. This is an ASP.NET MVC 4 application running .NET 4.5.1 and using the x86 build. Any ideas?
Comments: ** Comment from web user: posthope **
The `Bitmap`s used are built with `System.Drawing`. This seems to be the problem. If I explicitly set the `Format` property of `MagickImage` instances created from the `Bitmap`s to `MagickFormat.Gif`, then rendering to a stream works.
This works:
```
using (var collection = new MagickImageCollection()) {
foreach (Bitmap t in images) {
var imageMagicItem = new MagickImage(t) {
AnimationDelay = 100,
Format = MagickFormat.Gif
};
collection.Add(imageMagicItem);
}
collection.Optimize();
using (var stream = new MemoryStream()) {
collection.Write(stream);
collection.ForEach(i => i.Dispose());
return stream.ToArray();
}
}
```
My app also dies if I use anything other than `Format = MagickFormat.Gif`. For performance, I wanted to try `Format = MagickFormat.Gif` but didn't work. Hope this helps.