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

I have error with reading png.

Mar 2, 2016 at 10:22 AM
Hello I'm using next code and have some exceptions. This file generates by Aspose library. There are many another files that generated by Aspose libray and everything is okay. But this one doesn't work. On every time when Aspose generates new file it can't be read with MagickImage. Could you please help me? Thanks.
  using (var collection = new MagickImageCollection())
                    var t = new MagickImage(Path.Combine(Directory.GetCurrentDirectory(), "Templates","1.png"));
                catch (Exception ex)
Read Exception D:\PROJECTS STUDY\C#\MagickNETTester\MagickNETTester\bin\Debug\Templates\1.png' @ error/png.c/MagickPNGErrorHandler/1650

Corrupt image
D:\PROJECTS STUDY\C#\MagickNETTester\MagickNETTester\bin\Debug\Templates\1.png' @ error/png.c/ReadPNGImage/4020![Image]

This file here:
Mar 5, 2016 at 7:06 PM
Edited Mar 5, 2016 at 7:17 PM
The file that is being created is corrupt. ImageMagick/Magick.NET is very picky about invalid files. Your image has an extra incorrect IDAT chunk. I think you will need to have a chat with Aspose so they can fix this for you.


There is however a way that you could 'fix' the file. When you look at the last few bytes of the file you will see this:
0010000: 0e40 075e 0000 fff4 4944 4154 35af 061e  .@.^....IDAT5...
0010010: 0000 0000 4945 4e44 ae42 6082 0a         ....IEND.B`..
The block before IDAT specifies the length. And when you convert 0000 fff4 to an integer it will become 65524. The problem is that your file does not contain this much data. When you change 0000 fff4 to 0000 0000 the length of this block becomes zero and you can read this file. You probably need to test with a couple of files but I think you should be able to 'fix' the file by loading it into a bytestream and modify the length of the last IDAT record.