internal static void GetScreenShot( )
{
//获得当前屏幕的大小
Rectangle rect = new Rectangle();
rect = Screen.AllScreens[0].WorkingArea;
//计算图片的大小,因为图片的长和宽有可能超过目前屏幕的大小
//创建一个以当前屏幕为模板的图象
Control ctl = new Control();
Graphics g1 = ctl.CreateGraphics();
//创建以屏幕大小为标准的位图
Image MyImage = new Bitmap(rect.Width ,rect .Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
//得到屏幕的DC
IntPtr dc1 = g1.GetHdc();
//得到Bitmap的DC
IntPtr dc2 = g2.GetHdc();
//调用此API函数,实现屏幕捕获
BitBlt(dc2, 0, 0, rect.Width, rect.Height, dc1, 0, 0, 13369376);
//释放掉屏幕的DC
g1.ReleaseHdc(dc1);
//释放掉Bitmap的DC
g2.ReleaseHdc(dc2);
//以JPG文件格式来保存
//Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
//return MyImage.GetThumbnailImage(control.Width, control.Height, myCallback, IntPtr.Zero);
MyImage.Save("D:\\aa.jpg");
}
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, //目标设备的句柄
int nXDest, //目标对象的左上角的X坐标
int nYDest, //目标对象的左上角的X坐标
int nWidth, //目标对象的矩形的宽度
int nHeight, //目标对象的矩形的长度
IntPtr hdcSrc, //源设备的句柄
int nXSrc, //源对象的左上角的X坐标
int nYSrc, //源对象的左上角的X坐标
System.Int32 dwRop //光栅的操作值
);
{
//获得当前屏幕的大小
Rectangle rect = new Rectangle();
rect = Screen.AllScreens[0].WorkingArea;
//计算图片的大小,因为图片的长和宽有可能超过目前屏幕的大小
//创建一个以当前屏幕为模板的图象
Control ctl = new Control();
Graphics g1 = ctl.CreateGraphics();
//创建以屏幕大小为标准的位图
Image MyImage = new Bitmap(rect.Width ,rect .Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
//得到屏幕的DC
IntPtr dc1 = g1.GetHdc();
//得到Bitmap的DC
IntPtr dc2 = g2.GetHdc();
//调用此API函数,实现屏幕捕获
BitBlt(dc2, 0, 0, rect.Width, rect.Height, dc1, 0, 0, 13369376);
//释放掉屏幕的DC
g1.ReleaseHdc(dc1);
//释放掉Bitmap的DC
g2.ReleaseHdc(dc2);
//以JPG文件格式来保存
//Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
//return MyImage.GetThumbnailImage(control.Width, control.Height, myCallback, IntPtr.Zero);
MyImage.Save("D:\\aa.jpg");
}
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, //目标设备的句柄
int nXDest, //目标对象的左上角的X坐标
int nYDest, //目标对象的左上角的X坐标
int nWidth, //目标对象的矩形的宽度
int nHeight, //目标对象的矩形的长度
IntPtr hdcSrc, //源设备的句柄
int nXSrc, //源对象的左上角的X坐标
int nYSrc, //源对象的左上角的X坐标
System.Int32 dwRop //光栅的操作值
);