This project has moved and is read-only. For the latest updates, please go here.

Pixel Cache

Oct 13, 2014 at 5:20 PM
I'm getting an error when trying to convert an SVG to a PNG or JPG. I'm getting this error:

Permission denied @ error/cache.c/OpenPixelCache/3533

I'm sure what I'm doing wrong - anybody else run into this one, and what am I missing?

Thanks
Oct 13, 2014 at 5:42 PM
Can you post a code example? How are you reading the svg file?
Oct 13, 2014 at 5:53 PM
about as bare bones as you can get....
 // Read SVG image from file
 using (MagickImage image = new MagickImage(sourceName.Value.ToString()))
 {
    image.Format = (MagickFormat)Enum.Parse(typeof(MagickFormat), fileType.Value.ToString(), true);
    //image.Format = MagickFormat.Png;
    image.Write(string.Concat(targetName.Value.ToString(), ".", fileType.Value.ToString()));
 }
var returnCollection = new SimpleExpressionValueCollection
 {
   {"returnValue", new Value("Success: EP called")}
 };
Oct 13, 2014 at 6:00 PM
Edited Oct 13, 2014 at 6:12 PM
Are you using the latest version? And do you have this problem with every SVG file or a only with a specific file?

Edit: After taking a look at the ImageMagick code it seems like it cannot open pixel cache on disk. You might not have write permissions on the temp directory? You can change the temp dir with the following code:
MagickNET.SetTempDirectory(@"C:\YourFolder");
Oct 13, 2014 at 6:10 PM
I believe it's the latest - it's 7.0.03 file - and 7.0.0.0003 for the Product...

My original test file does still seem to work, it could be something with the file - not sure how to attach a file....
Oct 13, 2014 at 6:14 PM
Edited Oct 13, 2014 at 6:31 PM
It seems we cross posted. Can put your file on something like dropbox?

p.s. 7.0.0.0004 is the latest and 7.0.0.0005 will be published very soon.
Oct 13, 2014 at 6:35 PM
Okay - I tried the SetTempDirectory you mentioned, I put it in the same directory as the file to no avail. I'll download the latest and see if I have any luck, and here's a link to the file giving trouble:

https://www.dropbox.com/s/raztbs9n4w05v4h/SVG_Image_1.svg?dl=0

Thanks
Oct 13, 2014 at 6:50 PM
I'm thinking this is actually file issue. On another machine - it will create the output, however, there's nothing in it other than a white square....
Oct 13, 2014 at 7:07 PM
Edited Oct 13, 2014 at 7:12 PM
Your SVG file is creating a ridiculously large image, the dimensions are 37107x31865. The svg reader use a byte per pixel for each channel. This will result in an image that uses 37107 * 31865 * 4 (RGBA) = 4729658220 bytes = 4.7 gigabytes. If you are using an x86 build of Magick.NET it will probably fail to allocate that much memory and use disk cache instead. And you will need that much space available in your temp folder. And if you are using the Q16 version of Magick.NET the amount of memory will be doubled after you load the image.
Oct 13, 2014 at 8:56 PM
It appears to fail even with the 64bit version as well - and with the newer DLL, I get this error: Memory allocation failed

Is there a way to scale down the SVG if I find it too large?
Oct 15, 2014 at 7:16 AM
Edited Oct 15, 2014 at 7:16 AM
The could scale it down by lowering the DPI (Density):
MagickReadSettings settings = new MagickReadSettings()
{
  Density = new MagickGeometry(1) // This is just an example
};

using (MagickImage image = new MagickImage("SVG_Image_1.svg", settings))
{
}
Oct 15, 2014 at 12:31 PM
Great - thanks for the help - I'll give it a shot.