小编nvr*_*nvr的帖子

从捕获屏幕截图中删除内存

你好,我有一个问题.我有一个设置来捕获我的WebBrowser控件的屏幕截图:

public static class Utilities
{
    public const int SRCCOPY = 13369376;

    public static Image CaptureScreen()
    {
        return CaptureWindow(User32.GetDesktopWindow());
    }

    public static Image CaptureWindow(IntPtr handle)
    {

        IntPtr hdcSrc = User32.GetWindowDC(handle);

        User32.RECT windowRect = new User32.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 …
Run Code Online (Sandbox Code Playgroud)

c# screenshot winforms

2
推荐指数
1
解决办法
803
查看次数

标签 统计

c# ×1

screenshot ×1

winforms ×1