views:

76

answers:

2

How can I copy the image in the clientrectangle of my form to a bitmap in memory? I know how to go from bitmap to form, but not the other way around. Thanks!

A: 

Assuming you're referring to the BackgroundImage property of the form.

var bmp = ((Bitmap)this.BackgroundImage);
Mark H
I think the OP is interested in a "Print Screen"-like bitmap, i.e. a bitmap containing the entire client rect of the form.
Andreas Rejbrand
Yes, that's exactly what I mean. I used a .bmp file for the form's background image, so it would work just as well to retrieve the .bmp file's image for the bitmap in memory. But I'm stumped.
Jimmy
@Jimmy, you just need to access the BackgroundImage property. This returns an Image object, which is the in-memory representation of an image
Thomas Levesque
+1  A: 

You can use the DrawToBitmap() method. Mostly works, but you might have controls that don't implement it, like RTB or 3rd party controls. The backup method is Graphics.CopyFromScreen().

Hans Passant
This should work. Thanks!
Jimmy