Is it possible to BitBlt directly on to a GDI+ bitmap?
Posted
by
jnm2
on Stack Overflow
See other posts from Stack Overflow
or by jnm2
Published on 2011-01-01T15:02:45Z
Indexed on
2011/01/01
17:54 UTC
Read the original article
Hit count: 241
I am trying to BitBlt from an HBITMAP to a GDI+ bitmap. I tried this, but nothing happens:
Bitmap Buffer = New Bitmap(608, 392)
Graphics BufferGraphics = Graphics.FromImage(Buffer);
IntPtr hBufferDC = BufferGraphics.GetHdc();
...
BitBlt(hBufferDC, x, y, width, height, hInputDC, 0, 0, SRCCOPY);
EDIT: Apparently the hDC doesn't work if I acquire it and then much later use it with BitBlt. I needed to make sure the hDC was still valid. This is the solution:
Bitmap Buffer = New Bitmap(608, 392)
Graphics BufferGraphics = Graphics.FromImage(Buffer);
...
IntPtr hBufferDC = BufferGraphics.GetHdc();
BitBlt(hBufferDC, x, y, width, height, hInputDC, 0, 0, SRCCOPY);
BufferGraphics.ReleaseHdc(hBufferDC);
Does anyone know why this change is necessary? Why might it not work to use an hDC that was gotten earlier as in the first example?
© Stack Overflow or respective owner