ขณะนี้ฉันกำลังจับภาพหน้าต่างสแนปช็อตโดยใช้ GDI32.dll แม้ว่าฉันจะมีปัญหากับ Hardware Accelerated Windows ซึ่งฉันสงสัยว่ามีวิธีหลีกเลี่ยงหรือไม่
ฉันพบโค้ดที่น่าทึ่งนี้ที่นี่:
public static Image CaptureWindow(IntPtr handle)
{
IntPtr hdcSrc = User32.GetWindowDC(handle);
Rect windowRect = new Rect();
User32.GetWindowRect(handle, ref windowRect);
int width = windowRect.Right - windowRect.Left;
int height = windowRect.Bottom - windowRect.Top;
IntPtr hdcDest = Gdi32.CreateCompatibleDC(hdcSrc);
IntPtr hBitmap = Gdi32.CreateCompatibleBitmap(hdcSrc, width, height);
IntPtr hOld = Gdi32.SelectObject(hdcDest, hBitmap);
Gdi32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, SRCCOPY);
Gdi32.SelectObject(hdcDest, hOld);
Gdi32.DeleteDC(hdcDest);
User32.ReleaseDC(handle, hdcSrc);
Image image = Image.FromHbitmap(hBitmap);
Gdi32.DeleteObject(hBitmap);
return image;
}
ซึ่งใช้ได้กับทุกหน้าต่างยกเว้นหน้าต่าง Chrome ของฉัน การปิดใช้งานการเร่งด้วยฮาร์ดแวร์ใน Chrome แก้ไขปัญหานี้แล้ว แต่ฉันไม่ต้องการทำเช่นนี้
ใครมีข้อเสนอแนะ / วิธีแก้ไขสำหรับปัญหานี้?
ขอบคุณสำหรับความช่วยเหลือใด ๆ
-พอล