MagickNET exception when resample PixelCacheAllocationFailed

669 Views Asked by At

I use MagickNET in a ASP .NET application. Usually it's works but sometimes with somes files (.jpg, .png) I receive an exception when I resample the picture with another DPI

ImageMagick.MagickResourceLimitErrorException: iisexpress.exe: PixelCacheAllocationFailed `D:\Data\IT Tools and Applications\Code\Zola\ZolaIntranet\Upload\Temp\4ffe031b-b559-4b5c-8f88-e1a5b8e4fbe7.jpg' @ error/cache.c/OpenPixelCache/3369

Here the line where the exception happens :

 tmpImage.Resample(new PointD(300,300));

When I tried to use a smaller DPI (72 or less) I got another exception :

ImageMagick.MagickCacheErrorException: iisexpress.exe: UnableToExtendCache 'D:\Data\IT Tools and Applications\Code\Zola\ZolaIntranet\Upload\Temp\42458df9-f7ee-4e4b-abfd-628317b4b7eb.jpg': Invalid argument @ error/cache.c/OpenPixelCache/3536 ---> ImageMagick.MagickCacheErrorException: iisexpress.exe: UnableToExtendCache

Can someone have an idea ?

1

There are 1 best solutions below

0
On BEST ANSWER

For one or another reason, for few pictures in PNG format ImageMagick cant't find the density of the picture. You have to specify a density before calling Resample() function and that resolve my problem.

PointD density = new PointD(300,300);

tmpImage.Density = density;
tmpImage.Resample(density);
tmpImage.Write(image);