我想使用我一直使用的PrintWindow方法来捕获一个窗口。
RECT rc;
GetClientRect(hwnd, out rc); //The process window handler
Bitmap bmp = new Bitmap(rc.right, rc.bottom, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics gfxBmp = Graphics.FromImage(bmp);
IntPtr hdcBitmap = gfxBmp.GetHdc();
PrintWindow(hwnd, hdcBitmap, 1);
gfxBmp.ReleaseHdc(hdcBitmap);
gfxBmp.Dispose();
bmp.Save("test.png");
在这个特定的游戏流程中,当调用Printwindow函数时,窗口很快变空,因此有时保存的图像完全是白色的。
所以我尝试使用BitBlt:
Bitmap bmp = new Bitmap(rc.right, rc.bottom, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics gfxBmp = Graphics.FromImage(bmp);
IntPtr dest = gfxBmp.GetHdc();
IntPtr source = GetWindowDC(hwnd);
BitBlt(dest, 0, 0, rc.width, rc.height, source, 0, 0, 13369376);
bmp.Save("test.png");
但是使用上述代码保存的图像完全是黑色的。
有没有办法防止PrintWindow使过程窗口闪烁那个"白层"?如果不可能,BitBtl应该为我解决这个问题,但我的代码有什么问题吗?
谢谢