It's been a few years since my last foray into GDI, but I don't remember having an issue like this before. I am not getting an exception, but BitBlt is returning 0 (False), checking GetLastWIN32Error shows 6. Which appears to be an invalid handle. And the destination image remains blank.
I added in calls to SelectObject as well, but that shouldn't and didn't effect the invalid handle error.
Any thoughts on what I'm missing?
void MySub()
{
var bmpSrc = new Bitmap("c:\\temp\\test.bmp", false);
var bmpDst= new Bitmap(1000, 1000);
var gSrc = Graphics.FromImage(bmpSrc);
var gDst = Graphics.FromImage(bmpDst);
IntPtr HDCSrc = gSrc.GetHdc();
IntPtr HDCDst = gDst.GetHdc();
if (!BitBlt(HDCDst, 0, 0, 55, 94, HDCSrc, 0, 0, SRCCOPY))
{
int er = Marshal.GetLastWin32Error();
MessageBox.Show(er.ToString());
}
gDst.ReleaseHdc(HDCDst);
gSrc.ReleaseHdc(HDCSrc);
pictureBox1.Image = iDst;
}
public static long SRCCOPY = 0x00CC0020;
[DllImport("gdi32.dll", CallingConvention = CallingConvention.ThisCall, SetLastError = true)]
public static extern bool BitBlt(
IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, long dwRop);