> [...]
> Is there any way to export a region of the Graphics object into a
> Bitmap without using CopyFromScreen?
That depends on where you got the Graphics object. But not per se, no.
You draw _into_ Graphics objects, not _from_ them.
> Or, is there a CopyFromHDC() or equivalent?
Depending on exactly what you're trying to do, you might want to look at
Control.DrawToBitmap(), or possibly at using p/invoke to send a WM_PRINT
or WM_PRINTCLIENT message to the control in question.
It is possible something in WPF would do what you want, but I don't know
anything about that.
Pete
rory.groves@gmail.com - 12 Jan 2008 15:39 GMT
> That depends on where you got the Graphics object. But not per se, no.
> You draw _into_ Graphics objects, not _from_ them.
I do have access to the background control's graphics object, but, as
i mentioned, don't know how to "extract" the controul's bitmap into
another bitmap without using CopyFromScreen().
Here is a simplified representation of my code:
Rectangle rc = new
Rectangle(this.PointToScreen(foregroundControl.Location),
foregroundControl.Size);
using (Bitmap bitmap = new Bitmap(rc.Width, rc.Height,
PixelFormat.Format32bppArgb))
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(rc.Left, rc.Top, 0, 0, rc.Size);
foregroundControl.BackBitmap = bitmap;
}
foregroundControl.Invalidate(true);
Again, to re-iterate, CopyFromScreen() includes overlapping windows
and therefore messes up the foregroundControl's appearance. I need to
figure out how to copy the backgroundControl's bitmap without using
CopyFromScreen.
Thanks