Crunch Mode Blog - A State of Mind by Developers at D2Soft Technologies

Like us on Facebook

Magick.NET freezes when using resize()

I have been debugging an issue with some code that uses the Magick.NET wrapper for ImageMagick.  In the code, I do an image resize of a local stored file and set a maximum size in pixels (maxSize = 200):

ImageMagick.MagickImage magick = new ImageMagick.MagickImage(file);
magick.Format = ImageMagick.MagickFormat.Jpeg;
magick.Resize(maxSize, maxSize);
magick.Write(fileOut);
magick.Dispose();


However, it turns out that this code under ASP.NET using the .NET Framework 4 simply freezes when executing the magick.Resize() method.  No error or timeout associated, only an iisreset would stop the process.  After much search and testing, I found what seems to be a working solution:

ImageMagick.MagickImage magick = new ImageMagick.MagickImage(file);
magick.Format = ImageMagick.MagickFormat.Jpeg;
magick.Resize(new ImageMagick.MagickGeometry(maxSize, maxSize));
magick.Write(fileOut);
magick.Dispose();


As you can see, I simply set the resize dimension using a MagickGeometry object.  I don't know why, but after doing this, the Resize() method works every time.

Post your Comment: