Verify image

talahaski

Active member
Joined
Apr 29, 2004
Messages
35
Is there an easy way to verify a file selected by the user is actually a image file and not some other file that happens to have a image extension or if the image file is corrupt.

Im using a openfiledialog to get the image.
The user selects a jpg file, but its possible this file is corrupt or is not a true jpg file.

I could try to display the file in a picturebox and use a try/catch, but I dont want to display it, I just want to quickly verify if its actually a image or not.

Using VB .NET
 
Couple of things:

1) You can try creating an Image object (which wouldnt be displayed, just exist in memory). If it fails, youve got a bad file
2) You can read the file using a BinaryReader and check the file header for the image type. Youd have to get the header info for the various graphics formats from here.

Personally, Id got with the first choice, quick and easy. :)
 
Thanks

I went ahead with Option 1, although I think I may need to learn more about option 2 at some later stage because I want to be able to add my own image tags to jpg files. But thats another story.
 
Back
Top