How to check JPEG image in C # /. Net is not damaged

I need to be able to check if the JPEG image is valid and not damaged. This is not the same as question 210650 , which simply asks to verify that it is, in fact, a JPEG image. Download from a confirmation image, for example:

var testJpg = Bitmap.FromStream(filename, useEmbeddedColorManagement, validateData); 

will not throw an exception for cropped images. Currently, our solution is to try to open the file with an external GD script and analyze any errors that occurred from gdImageCreateFromJpeg.

 gdImagePtr im; im = gdImageCreateFromJpeg(testFile); fclose(in); 

But somewhere there should be some kind of .Net code that checks that JPEG is not only valid, but contains a complete image?

0
source share
2 answers

By taking the JPEG link structure from Wikipedia , maybe you can look for EOI bytes from the stream?

+2
source

There is pnetlib that provides interop to jpeglib using C # , as soon as you have that you can check what you want.
You can try using JpegReader , maybe this will give you an error out of the box.

0
source

Source: https://habr.com/ru/post/905889/


All Articles