Save pictureBox to Bmp problem

Farek

Member
Joined
Oct 1, 2003
Messages
12
Hello,

Ive drawn a picture using the picturebox_paint event.
ex.
Code:
 e.Graphics.FillRectangle(mybrush, x * 16, y * 16, 16, 16)

Later I want to save the picture in the picturebox. But the picturebox.image is Nothing. BackgroundImage is also Nothing.

How do you save the content in the picturebox to a bmp file if you havent specifically added an image through picturebox.Image property?

Best Wishes,
Farek
 
Farek said:
Hello,

Ive drawn a picture using the picturebox_paint event.
ex.
Code:
 e.Graphics.FillRectangle(mybrush, x * 16, y * 16, 16, 16)

Later I want to save the picture in the picturebox. But the picturebox.image is Nothing. BackgroundImage is also Nothing.

How do you save the content in the picturebox to a bmp file if you havent specifically added an image through picturebox.Image property?

Best Wishes,
Farek
Im not sure about saving an image drawn using e.Graphics as Im not sure how you could get hold of the object it is drawn to. There is a simpler solution, in the paint method just do somthing like this.

C#:
Bitmap myBitmap = new Bitmap(800, 600);
Graphics g = Graphics.FromImage(myBitmap);
g.FillRectangle(mybrush, x * 16, y * 16, 16, 16);
g.Dispose;
this.Image = myBitmap;
 
You might want to consider drawing the image to a bitmap and setting that bitmap as the picture boxs image.

If you are using .Net 2.0, and you are drawing to the control in the Paint event you can also draw the control to a bitmap using the DrawToBitmap method of the control, but this will also draw the borders of the picture box if there are any, and is kind of a round-a-bout way of doing things anyways.
 
Back
Top