3

i'm trying to load image from local disk, and it's working. But my problem is that i'd like to check if image size is valid or not before loading , and if not - then MessageBox.Show("No image!");

say if image size is zero it should say like "Invalid Image"

and is it possible to check the file extension also

user682417
  • 1,478
  • 4
  • 25
  • 46
  • 3
    You have to be more precise about what you call a "valid image size" – CharlesB Jun 23 '11 at 12:00
  • What do you mean if by 'size not valid' and 'not in a folder'? Anything other than a 0 byte file is a valid image, albeit a rather small one. – bobbyalex Jun 23 '11 at 12:01
  • @Bobby: Unless it's corrupt, which is probably what he meant. I assume the question is looking to load an image file and validate the dimensions, so that if valid dimensions are returned we can assume the image file is "valid". – Yuck Jun 23 '11 at 12:02
  • Yeah that's probably what he meant. If the file is truly corrupt or not an actual image loading it should result in an exception. But if the image is visually corrupt I doubt if there is a way to find that. – bobbyalex Jun 23 '11 at 12:05
  • @user682417: You could use Image.FromFile. It will throw an exception if the image is not in a supported GDI format.OutOfMemoryException I think. But I guess you already knew that. Are you looking for something else? – bobbyalex Jun 23 '11 at 12:08

2 Answers2

2

Getting image dimensions without reading the entire file

Community
  • 1
  • 1
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
2

Note this is for checking size of file on disk

MSDN FileInfo.Length says that it is "the size of the current file in bytes."

or

You can get the size of image like

Get size of file on disk

or

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/85bf76ac-a254-41d4-a3d7-e7803c8d9bc3

and putting this thing in if you can show the msg you want

Community
  • 1
  • 1
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263