4 Replies - 2554 Views - Last Post: 13 January 2011 - 08:10 AM Rate Topic: -----

#1 MarmiteX1  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 159
  • Joined: 17-October 09

Corrupted Image checking

Posted 13 January 2011 - 06:01 AM

Hi,

I am procesing some product images in my console app and some the images seem to be corrupted.

I firstly check if the file exists

try 
{
if(File.Exists(filepath)==true)
{
  //process it
   GenerateImage(filePath);
  //notify user using my own email utility class
  //EmailUtil.SendEmail(userId)

}
}
catch(.......)
{
 Console.WriteLine(ex.message);
}



I get an exception:

"Parameter is not valid".

When i go to view the image in my ProductImages folder and select the image that is causing the issue I get the following:

"Windows Photo Viewer cannot open this file since the file is empty."

Is there an inbuilt functionality available in the .NET framework by any chance to not to process corrupted images? Or do I have to ensure I dont deal with corrupted images in the first place?

Any thoughts on the above would be much appreciated.

Thanks in advance

This post has been edited by MarmiteX1: 13 January 2011 - 06:03 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Corrupted Image checking

#2 Fungle  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 256
  • View blog
  • Posts: 337
  • Joined: 06-March 10

Re: Corrupted Image checking

Posted 13 January 2011 - 06:15 AM

From what I gather, The parameter is not valid error could be referencing the actual path itself instead of the destination directory.

Also if the photo viewer claims the file is empty then have you tried using a different image? or checking that the image is in the project directory in the first place?
Was This Post Helpful? 0
  • +
  • -

#3 MarmiteX1  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 159
  • Joined: 17-October 09

Re: Corrupted Image checking

Posted 13 January 2011 - 06:24 AM

View PostFungle, on 13 January 2011 - 05:15 AM, said:

From what I gather, The parameter is not valid error could be referencing the actual path itself instead of the destination directory.

Also if the photo viewer claims the file is empty then have you tried using a different image? or checking that the image is in the project directory in the first place?



I pasted the filepath in windows explorer and it can find the file.

I've tried a different image and it works. I think the issue lies with the image itself don't you think?

Thanks,
Was This Post Helpful? 0
  • +
  • -

#4 Fungle  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 256
  • View blog
  • Posts: 337
  • Joined: 06-March 10

Re: Corrupted Image checking

Posted 13 January 2011 - 06:25 AM

Yeah it seems that somehow your original image has turned into a shell of what it once was ^^

Must of been the image then.
Was This Post Helpful? 1
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5678
  • View blog
  • Posts: 12,217
  • Joined: 02-June 10

Re: Corrupted Image checking

Posted 13 January 2011 - 08:10 AM

You could also check the size of the file. If it is 0k for example you know it's fraked.
You could try loading the image as a byte array. If that fails you know it's fraked.
You simply can't trust Image.FromFile(stringPathToFile); from the framework because it sucks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1