Search code examples
asp.netthumbnailssystem.drawing

asp.net generating thumbnails "A generic error occurred in GDI+."


im using asp.net system.drawing in order to generate a thumbnail after the image finish uploading using this code:

//programmImages -- the id of the fileupload control

string path = "~/User/" + "progimgs/" + programmImages.FileName;
string thumbPath = "~/User/" + "thums/" + programmImages.FileName;

programmImages.SaveAs(Server.MapPath(path));
programmImages.Dispose();

//generating the tumbnails
System.Drawing.Image thum = System.Drawing.Image.FromFile(Server.MapPath(path));

System.Drawing.Image createTumb = 
                           thum.GetThumbnailImage(250, 140, ()=>false, IntPtr.Zero);

createTumb.Save(thumbPath, ImageFormat.Jpeg);

im getting this erro "A generic error occurred in GDI+"

on this line "createTumb.Save(thumbPath, ImageFormat.Jpeg);"

what is the problem, thanks.


Solution

  • as Aristos pointed out i was missing the server.mappath from the thumbPath.