Windows Develop Bookmark and Share   
 index > Windows Forms General > A generic error occurred in GDI+.
 

A generic error occurred in GDI+.

I am trying to load an image from a physical location in the disk

and trying to save it to the disk using graphics object,

When i do that I face an error

"A generic error occurred in GDI+. "

here is the code ::

{

Image img = new Bitmap(800, 800, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

Image.FromFile(@"C:\Documents and Settings\mysettings\Desktop\seethis.tif");

string p =z + "\\"+ itemname ;

Graphics g = Graphics.FromImage(img);

g.DrawImage(img, 0, 0);

Directory.CreateDirectory(p);

img.Save(p, System.Drawing.Imaging.ImageFormat.Tiff);

img.Dispose();

}

Can you Please help me what to do??

I want to save the seethis.tif file to another location in the disk programatically.

BFL  Friday, March 07, 2008 7:39 AM

The problem is that you don't assign the Image.FromFile(...) to anything. You create a new Image, you call Image.FromFile(..) without assigning the result to an Image variable. Then you call Graphics.FromImage(img) and start painting that img on itself. So what you currently are doing is drawing img to img. This cannot be done and probably throws the generic GDI+ error.

You can just do:

Image img= Image.FromFile(...);

string p =z + "\\"+ itemname ;

Directory.CreateDirectory(p);

image.Save(p, ...);

And that is it. No graphics are needed.

www.qiosdevsuite.com  Sunday, March 09, 2008 3:34 PM

Could you please provide more details on exception you receive?

If you can't I suggest you to use Managed Debugging Assistants in order to retrieve more details:

http://msdn2.microsoft.com/en-us/library/d21c150d(VS.80).aspx

Vitaliy Liptchinsky  Friday, March 07, 2008 8:07 AM

The problem is that you don't assign the Image.FromFile(...) to anything. You create a new Image, you call Image.FromFile(..) without assigning the result to an Image variable. Then you call Graphics.FromImage(img) and start painting that img on itself. So what you currently are doing is drawing img to img. This cannot be done and probably throws the generic GDI+ error.

You can just do:

Image img= Image.FromFile(...);

string p =z + "\\"+ itemname ;

Directory.CreateDirectory(p);

image.Save(p, ...);

And that is it. No graphics are needed.

www.qiosdevsuite.com  Sunday, March 09, 2008 3:34 PM

Thanks for your response,

It is of great help to me.

BFL  Tuesday, March 11, 2008 1:39 PM

You can use google to search for other answers

Custom Search

More Threads

• GDI+ or Managed Direct X
• Bug in VS2005 with ContextMenuStrip??
• DirectX with c#
• Help me about ListView ?
• VB.NET - User input ????? Please help
• VU meter / LED bargraph for audio
• Code modularization
• Change property from another form
• InternetOpen,InternetConnect,InternetQueryOption
• .NET Applications on W2K Terminal Servers