Darren Young
Darren Young

Reputation: 11090

c# picturebox bitmaps

I have a picturebox that upon request, I save the current display to a bitmap.

My question is, how do I then load that same bitmap to the picturebox?

Thanks.

EDIT:

The only relevant code is: pictureBox1.DrawToBitmap(test1,pictureBox1.ClientRectangle);

The picture box contains graphics that I have written 'freehand' using the mouse. So you can use the mouse to write directly onto the screen when the left mouse is pressed.

Upvotes: 0

Views: 6591

Answers (2)

Cody Gray
Cody Gray

Reputation: 244692

You can assign any image to the picture box that you want during run-time. Just set the Image property of the picture box to the picture you want to be displayed.

For example, to display an image in a picture box from a file on your hard drive, you could use something like:

myPicBox.Image = Image.FromFile("C:\savedimage.bmp");

Or, your edit suggests that you have a bitmap object in memory that you want to display in the picture box. In that case, it's a simple matter of assigning that bitmap object to the Image property:

myPicBox.Image = test1;  //(where test1 is your bitmap object in memory)


Edit: Just in case you want to save the bitmap object that you created in memory to disk so that you can reload and use it later, check out the Save method of the Bitmap object:

test1.Save("C:\savedimage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

Upvotes: 2

Neil
Neil

Reputation: 5782

If I'm not mistaken, the picturebox should have an Image property that you can simply use to assign the Bitmap to.

Upvotes: 0

Related Questions