BitBlt not capturing windows in Hardware accelerated mode
Asked Answered
C

0

6

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

Catechetical answered 1/7, 2016 at 7:49 Comment(1)
Use CAPTUREBLT | SRCCOPY so you can also capture layered windows. A bit doubtful that it makes a difference, file a bug with the Chromium project.Doralyn

© 2022 - 2024 — McMap. All rights reserved.