I'm currently working on capturing window snapshots using GDI32.dll though I'm having an issue with Hardware Accelerated Windows that I was wondering if there was a way to circumvent.
I found this amazing bit of code here:
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;
}
which works for all windows except my chrome windows. Disabling Hardware Acceleration in chrome fixed this though I would prefer not to have to do this.
Anyone have any suggestions/ solutions for this problem?
Thanks for any and all help,
-Paul