簡體   English   中英

屏幕關閉時捕獲窗口

[英]Capture window when screen is off

我正在使用Native GDI +捕獲窗口“屏幕上”。 屏幕關閉時它不起作用(生成黑色圖像)。 我該如何解決? (我正在使用.Net 4.5)

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;
 }

據我所知,圖形驅動程序在沒有人接收時停止生成圖像,以節省電量。 這可能是您在屏幕“關閉”時無法捕獲圖像的原因。 當沒有人接收圖像時,在生成圖像時使用CPU和GPU以及總線電源是沒有意義的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM