Try somethimg like this...
Code:
private void GenerateThumb(string sourcepath, string folder, string prefix, int width,
bool overwrite, bool deletecurrupt)
{
double factor;
System.Drawing.Image thumbnail, fullimage;
string file = Path.GetFileName(sourcepath);
string filethumb = folder + (folder.EndsWith(@"\")? "" : @"\")
+ prefix + "." + file;
if(overwrite || (!overwrite && !File.Exists(filethumb)))
{
try
{
fullimage = System.Drawing.Image.FromFile(sourcepath);
factor = fullimage.Width/(double)width;
thumbnail = fullimage.GetThumbnailImage(width,
(int)(fullimage.Height/factor), null, IntPtr.Zero);
thumbnail.Save(filethumb, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch(OutOfMemoryException)
{
if(deletecurrupt)
File.Delete(sourcepath);
}
}
}
(tested)
The OutOfMemoryException is included since it is thrown when currupted pictures are read using FromFile. In the above sample the currupted file is deleted.
Hope it helps, Jacob.