How to save Graphics Objects to disk as Bitmaps

aewarnick

Well-known member
Joined
Jan 29, 2003
Messages
1,031
I read how to save a Graphics object to disk from the web and this is the method I came up with, however, it saves a black image with no picture at all!! What am I doing wrong?
C#:
G.DrawImage((Image)Ims[tick], R);
//System.Drawing.Drawing2D.GraphicsState GS= G.Save();
Bitmap B=new Bitmap(R.Width, R.Height, G);
B.Save("D:\\Pic.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
G is a graphics object. R is a rectangle.
 
You cant do this. You must save the original bitmap that you got your Graphics from. The Bitmap constructor you are using only uses the resolution settings of the graphics object passed in.

Graphics objects dont have contents, they are meant to modify the contents of the bitmap they originated from. If you got the graphics object from a surface, youll have to rethink something.
 
No, thats what you use to get a Graphics instance from an existing bitmap.
 
What I want to do is something like ms paint does. Allow the user to draw and then save their work as a picture to disk. How do I do that?
 
Just keep a bitmap instance around in memory and draw on that. Display it to screen when needed.
 
Back
Top