none
How to handle ( Check) Corrupt image file through C#.

    Question

  • Hi,

     

            I would like to know the method of handling corrupt image file in C#. it does not give any exception .

     

    Thanks.

    With Regards,

    Lingaraj Patra

    Thursday, February 22, 2007 2:31 PM

Answers

  • Hi,

     I am not completely following your question,  you are saying that you loaded an image and the picture was corruped but no exception was thrown?  If the pixel data is corrupted then there is really nothing the Image class can do,  only if the picture header information is incorrect will it be able to determine that the image data is invalid.  If you really want you could do something like create an MD5 hash of the image file when it is not corrupt,  then before loading the image you can hash it again and if the two hashes are different then you know the file has been modified unexpectedly,  this does not guarantee the data is corrupt,  someone could have just modified the image, but it does let you know the image wa smodified since the last time you checked.

     

    Mark

    Thursday, February 22, 2007 4:34 PM
  • Hi Rizwan / Mark,

                           Thanks for your valuable information.  how to check the header of the image in c# ?

    With Regards,

    Lingaraj Patra

                    

    Monday, February 26, 2007 12:59 PM

All replies

  • Hi,

     I am not completely following your question,  you are saying that you loaded an image and the picture was corruped but no exception was thrown?  If the pixel data is corrupted then there is really nothing the Image class can do,  only if the picture header information is incorrect will it be able to determine that the image data is invalid.  If you really want you could do something like create an MD5 hash of the image file when it is not corrupt,  then before loading the image you can hash it again and if the two hashes are different then you know the file has been modified unexpectedly,  this does not guarantee the data is corrupt,  someone could have just modified the image, but it does let you know the image wa smodified since the last time you checked.

     

    Mark

    Thursday, February 22, 2007 4:34 PM
  • Mark is absoluteyly right, There is no way to detect the distortion in image but what can be checked is only if the header of the image is not corrupt. The idea about creating a hash will also tell only that id the image was modified since the original hash was created.

    Best Regards,

    Rizwan aka RizwanSharp

    Friday, February 23, 2007 2:31 PM
  • Hi Rizwan / Mark,

                           Thanks for your valuable information.  how to check the header of the image in c# ?

    With Regards,

    Lingaraj Patra

                    

    Monday, February 26, 2007 12:59 PM