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

Commented Unassigned: ToByteArray and Write(Stream) for MagickImageCollection kill application [1169]

$
0
0
I have been trying out Magick.NET in my web application with success until I attempted to create animated gifs. When I try to call `collection.ToByteArray()` or `collection.Write(stream)` the application crashes. No exception, just crashes.

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.


Viewing all articles
Browse latest Browse all 1011

Trending Articles



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