Is there a way to read photo after CRC error?

Apr 14, 2015 at 6:43 AM
I have several photos that generate PNG CRC error:
ImageMagick.MagickCoderErrorException: IDAT: CRC error `' @ error/png.c/MagickPNGErrorHandler/1650 ---> ImageMagick.MagickCorruptImageErrorException: Corrupt image `' @ error/png.c/ReadPNGImage/4003
   --- End of inner exception stack trace ---
   at ImageMagick.MagickImage..ctor(Stream stream)
Here is an example of such image.

Yet those images can be viewed in windows.

I'm wondering is there a way to force Magick.NET to ignore CRC error or something like this to load this image? Like catch the exeption and if it contains "CRC error" then try to load with some other method/parameters?
Apr 14, 2015 at 3:17 PM
I just checked the PNG coder in ImageMagick and it turns out I could possibly tweak it to 'return an image' when an error has occurred. I will have to talk about this with the rest of the team first. I will get back to you in a couple of days.
Apr 15, 2015 at 8:35 AM
Edited Apr 15, 2015 at 8:35 AM
Thanks! Maybe this kind of "ignore CRC Errors" shouldn't be a default behavior and should be specified as option via MagickReadSettings.
Apr 23, 2015 at 9:47 PM
In the new version of Magick.NET that has just been published you will be able to do read the image even though it is corrupt. You can do that with the new class PngReadDefines. Below is an example:
MagickReadSettings settings = new MagickReadSettings()
    Defines = new PngReadDefines()
        PreserveCorruptImage = true

using (MagickImage image = new MagickImage())
        image.Read("Corrupt.png", settings);
    catch (MagickCoderErrorException)
        // Do something with the image.
Apr 24, 2015 at 6:23 PM
Thank you!
That works perfectly.