Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

I've drawn a picture using the picturebox_paint event.

ex.

 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 haven't specifically added an image through picturebox.Image property?

 

Best Wishes,

Farek

Posted
Hello,

 

I've drawn a picture using the picturebox_paint event.

ex.

 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 haven't specifically added an image through picturebox.Image property?

 

Best Wishes,

Farek

I'm not sure about saving an image drawn using e.Graphics as I'm 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.

 

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;

Anybody looking for a graduate programmer (Midlands, England)?
  • Leaders
Posted

You might want to consider drawing the image to a bitmap and setting that bitmap as the picture box's 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.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...