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?