高效,低消耗,桌面拷贝
public void CaptureWindow(IntPtr dest)
{
IntPtr hdcSrc = User32.GetWindowDC(User32.GetDesktopWindow());
IntPtr hdcDest = GDI32.CreateCompatibleDC(dest);
using (Graphics grDest = Graphics.FromHwnd(dest))
{
IntPtr hdcDest1 = IntPtr.Zero;
hdcDest1 = grDest.GetHdc();
GDI32.SetStretchBltMode(hdcDest1, 4);
if (!GDI32.StretchBlt(hdcDest1, 0, 0, testpb.Width, testpb.Height, hdcSrc, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, GDI32.SRCCOPY))
{
}
if (hdcDest1 != IntPtr.Zero) grDest.ReleaseHdc(hdcDest1);
{ }
}
GDI32.DeleteDC(hdcDest);
User32.ReleaseDC(handle, hdcSrc);
}