How do I determine if an image that I have as raw bytes is corrupted or not. Is there any opensource library that handles this issue for multiple formats in C#?
Thanks
How do I determine if an image that I have as raw bytes is corrupted or not. Is there any opensource library that handles this issue for multiple formats in C#?
Thanks
Try to create a GDI+ Bitmap from the file. If creating the Bitmap object fails, then you could assume the image is corrupt. GDI+ supports a number of file formats: BMP, GIF, JPEG, Exif, PNG, TIFF.
Something like this function should work:
You may be able to limit the
Exception
to justArgumentException
, but I would experiment with that first before making the switch.EDIT
If you have a
byte[]
, then this should work:You can look these links for taking an idea. First one is here; Validate Images
And second one is here; How to check corrupt TIFF images
And sorry, I don't know any external library for this.