Last post Sep 15, 2011 06:12 AM by savindra.bandi
Jul 04, 2004 09:50 PM|jimmyLeander|LINK
Jul 06, 2004 11:29 AM|jaraco|LINK
Jul 06, 2004 11:45 AM|jaraco|LINK
Jul 06, 2004 05:35 PM|Qgyen|LINK
Nov 19, 2007 01:42 PM|shantanushukla|LINK
System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. WHEN YOU TRY TO SAVE A BITMAP
you can not save the same Bitmap whihch you loaded into the object as it is bieng used by the other process at the same time....
So first rename it and then try to save....
//Step 6 : Try to save the image
// this file is exclusively locked by BITMAP process so PERHAPS error may occur so first prefix the s_ before image
//Now save this image
ObjBitmap.Save(TargetPath + "s_" + tmpFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
//STEP 7 : CLEAN UP
//Destroy the Graphics Object
//DESTROY thE Bitmap Object and UNLOCK the file
//Delete the Temporarily Uploaded image
File.Delete(TargetPath + tmpFileName);
lblMessage.Text = "Stamping Done";
I hope this will be help full for you.... If you find this info helpfull please do not forget to mark it as answer
System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
Apr 30, 2008 03:37 AM|liammclennan|LINK
If this error is caused by permissions then there are two possible scenarios:
Jan 14, 2009 09:18 AM|radok|LINK
i did all solution but never solve this problem.
i gave full permission folder and dispose() all bitmap and grabhics. its nothing.
But i try this one : GC.Collect(); and its working. i think iis working process cannot permission overwrite same bitmap. Because
of bitmaps lifetime.
So i use Garbace Collector and solve this problem. My code is working fine.
Feb 01, 2009 09:46 AM|MinaSamy|LINK
thanks man that worked
Sep 10, 2009 08:46 PM|dacraka|LINK
Yea, just needed to do a .Dispose(); when done with the first System.Drawing.Image
Oct 09, 2009 05:28 AM|rajeev16mca2k5|LINK
I know its very old post. I am just posting due to the reason if some one will search this error & ma get solution.
I was also facing same error, i did lots of R&D. Actually i was saving files in a temporary folder after uploading. After that i was performing some operations on the image and saving resultant image in a different folder and deleting file in temporary folder.
Actually temporary folder is empty, after publishing , that temporary folder does not exist in published project. so, for saving file temporarily, it is not getting path.
then i have manually created empty temporary folder in published folder.
its working f9 now.
Nov 13, 2009 06:59 AM|Mellanie|LINK
thanks man that worked
Of course that worked! Thanks for advice :)
Feb 25, 2010 05:56 AM|hello.vickey|LINK
@dacraka Completly Agree with you,one need to dispose the objects insted of carry them further... have a look a
private void SaveAsThumbNail(int thumb_height, int thumb_width, FileUpload FileUpldCntrl, string imgPath)
myimage = System.Drawing.Image.FromFile(Server.MapPath(imgPath));
System.Drawing.Bitmap source_bitmap = new System.Drawing.Bitmap(myimage);
System.Drawing.Bitmap thumb_bitmap = new System.Drawing.Bitmap(thumb_width, thumb_height);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(thumb_bitmap);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle(System.Drawing.Brushes.White, 0, 0, thumb_width, thumb_height);
g.DrawImage(source_bitmap, 0, 0, thumb_width, thumb_height);
System.Drawing.Imaging.ImageCodecInfo Info = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();
System.Drawing.Imaging.EncoderParameters Params = new System.Drawing.Imaging.EncoderParameters(1);
Params.Param = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
thumb_bitmap.Save(Server.MapPath(imgPath), Info, Params);
catch (Exception ex)
CommonFunctions objcom = new CommonFunctions();
ex.Message.ToString(), HttpContext.Current, ex);
May 22, 2010 06:40 PM|hasibul2363|LINK
This is only for read and write permision. Just enable write permision on your folder.
hopeful it will solve your problem.
Jul 08, 2010 10:09 AM|rohitmahadik|LINK
as me was blocked on the same issue from last 3-4 days n tried a lot of different attempts for the same but not a single one turned out to be successful.
But finally today i got the solution.
After making it double sure that all the permissions are set to WRITE.
USE string filepath = Server.MapPath("./Images/");
string filepath = Server.MapPath("~//Images//");
the main issue was while mapping a virtual path
it starts the path from site folder
so we need to map with "." instead of "~"
I have tried the same solution on 3 different projects for the same problem.
all of them started working very smoothly.
All the best..... :)
Sep 15, 2011 06:12 AM|savindra.bandi|LINK
If you are getting that error , then I can say that your application doesn't have a write permission on some directory [where your trying to save or write image].
For example, if you are trying to save the Image from the memory stream to the file system , you may get that error.
I also faced that error when I was using Infragistics charts control , the control was trying to create a temporary chart in ChartImages folder and my application was not given the write permission.
Please if you are using XP, make sure to add write permission for the aspnet account on that folder.
If you are using windows server (2003,2008) or Vista, make sure that add write permission for the Network service account.
Hope it help some one.
gdi+ memory bitmap sclaing drawimage resizing