private static IntPtr CreateBitmap(IntPtr hWnd, int width, int height)
{ Bitmap retVal = new Bitmap(width, height); Graphics sGrap = Graphics.FromImage(retVal); IntPtr hdc = sGrap.GetHdc(); if (WinApi.PrintWindow(hWnd, hdc, 0))
{
sGrap.ReleaseHdc(hdc);
}
else
{
throw new Exception("截取窗体图片出错");
} return hdc;
} private static Bitmap CreateBitmap(IntPtr shdc, int x, int y, int width, int height)
{ Bitmap retVal = new Bitmap(width, height); Graphics dhcd = Graphics.FromImage(retVal); IntPtr dPtr = dhcd.GetHdc(); if (WinApi.BitBlt(dPtr, 0, 0, width, height, shdc, x, y, WinApi.SRCCOPY) == 0)
{
throw new Exception("区域截图错误");
}
else
{
dhcd.ReleaseHdc(dPtr);
} return retVal;
}//Api声明
public const int SRCCOPY = 0xcc0020;
[DllImport("gdi32.dll ")]
public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop); [DllImport("user32.dll")] public static extern bool PrintWindow( IntPtr hwnd, // Window to copy,Handle to the window that will be copied. IntPtr hdcBlt, // HDC to print into,Handle to the device context. UInt32 nFlags // Optional flags,Specifies the drawing options. It can be one of the following values. );
{ Bitmap retVal = new Bitmap(width, height); Graphics sGrap = Graphics.FromImage(retVal); IntPtr hdc = sGrap.GetHdc(); if (WinApi.PrintWindow(hWnd, hdc, 0))
{
sGrap.ReleaseHdc(hdc);
}
else
{
throw new Exception("截取窗体图片出错");
} return hdc;
} private static Bitmap CreateBitmap(IntPtr shdc, int x, int y, int width, int height)
{ Bitmap retVal = new Bitmap(width, height); Graphics dhcd = Graphics.FromImage(retVal); IntPtr dPtr = dhcd.GetHdc(); if (WinApi.BitBlt(dPtr, 0, 0, width, height, shdc, x, y, WinApi.SRCCOPY) == 0)
{
throw new Exception("区域截图错误");
}
else
{
dhcd.ReleaseHdc(dPtr);
} return retVal;
}//Api声明
public const int SRCCOPY = 0xcc0020;
[DllImport("gdi32.dll ")]
public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop); [DllImport("user32.dll")] public static extern bool PrintWindow( IntPtr hwnd, // Window to copy,Handle to the window that will be copied. IntPtr hdcBlt, // HDC to print into,Handle to the device context. UInt32 nFlags // Optional flags,Specifies the drawing options. It can be one of the following values. );
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货