c# 窗体截图

/// <summary>
/// 可以捕获超出屏幕大小的的截图
/// </summary>
/// <param name="hWnd"></param>
/// <returns></returns>
public static Image CaptureWindowScreen(IntPtr hWnd)
{
    RECT rect = new RECT();
    GetWindowRect(hWnd, ref rect);
    var width = rect.right - rect.left;
    var height = rect.bottom - rect.top;
    Image myImage = new Bitmap(width, height);
    Graphics myGraphics = Graphics.FromImage(myImage);
    var hdc = myGraphics.GetHdc();
    PrintWindow(hWnd, hdc, 0);
    myGraphics.Dispose();
    return myImage;
}

 

posted on 2024-04-02 14:39  空明流光  阅读(83)  评论(0编辑  收藏  举报

导航