Convert a Graphics object into Bitmap

Hi,

    I need to create a image using the Graphics Object. That means, in my system i'm drawing few lines and i want load it into a picture box. What i thaught was to convert the Graphics object into a bitmap and include the bitmap in the picture box. but i'm not sure how to do this. Can please tell me how to do this?

Thanks
lilanwAsked:
Who is Participating?
 
RomanPetrenkoConnect With a Mentor Commented:
Try something like this:
====
int width = 100,height=100;
Bitmap YourBMP = new Bitmap(width,height);
Graphics g = Graphics.FromImage(YourBMP);
///Draw anything you want on g
pictureBox1.Image = YourBMP;
====
0
 
ptmcompCommented:
The Graphics object is a drawing adapter to a device or image. The Graphics object does not contain an image. It's only a adapter to the screen buffer or a bitmap.
For your case it would be the easiest to paint on the bitmap like RomanPetrenko showed you above and then Draw the bitmap on your form or display it in a picture box. (Then the picture box does the drawing for you.)
0
 
RomanPetrenkoCommented:
I think the answer I gave is complete. Can it be graded?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.