Farek Posted April 12, 2006 Posted April 12, 2006 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 Quote
Cags Posted April 12, 2006 Posted April 12, 2006 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; Quote Anybody looking for a graduate programmer (Midlands, England)?
Leaders snarfblam Posted April 13, 2006 Leaders Posted April 13, 2006 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. Quote [sIGPIC]e[/sIGPIC]
Farek Posted April 18, 2006 Author Posted April 18, 2006 Thanks Thanks all, Working fine now :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.