A generic error occurred in GDI+

i have used the imgpaths into the server.mappath()
when going to save the image at the time , i have A generic error occurred in GDI+ Error.

            Graphics Grfx = Graphics.FromImage(bitmap);
            Grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            Grfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            Grfx.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            Grfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            Grfx.DrawImage(bitmap, 0, 0, wb.Width, wb.Height);

            using (Bitmap img = bitmap.Clone() as Bitmap)
            {
                Bitmap newimage = img.Clone(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), img.PixelFormat);
                newimage.Save(imgpaths, System.Drawing.Imaging.ImageFormat.Jpeg);  //Error:A generic error occurred in GDI+.
            }



            wb.Dispose();

Upvotes: 0

Views: 596

Answers (1)

Guffa
Guffa

Reputation: 700720

When reading an image from a file, the file will be kept open as long as that image object exists.

You have to dispose the original image object before you can save an image with the same file name.

Upvotes: 1

Related Questions