[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(int hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int hdcSrc, int nXSrc, int nYSrc, System.Int32 dwRop);
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern int CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, int lplnitData);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
public static extern int DeleteDC(int hdc);
private void button1_Click(object sender, EventArgs e)
{
int[] fenbianlv = new int[2];
fenbianlv[0] = Screen.PrimaryScreen.WorkingArea.Width;
fenbianlv[1] = Screen.PrimaryScreen.WorkingArea.Height;
int hdlDisplay;
Graphics gfxDisplay;
Bitmap bmp;
Graphics gfxBmp;
int hdlScreen;
int hdlBmp;
hdlDisplay = CreateDC("DISPLAY", null, null, 0);
gfxDisplay = Graphics.FromHdc((IntPtr)hdlDisplay);
bmp = new Bitmap(fenbianlv[0], fenbianlv[1], gfxDisplay);
gfxBmp = Graphics.FromImage(bmp);
hdlScreen = (int)gfxDisplay.GetHdc();
hdlBmp = (int)gfxBmp.GetHdc();
BitBlt(hdlBmp, 0, 0, fenbianlv[0], fenbianlv[1], hdlScreen, 0, 0, 13369376);
DeleteDC(hdlDisplay);
gfxDisplay.Dispose();
gfxBmp.Dispose();
string path = string.Format( "截图{0}.jpg",k.ToString());
bmp.Save(path);
k++;
MessageBox.Show("截图成功!");
}
|
|
| 40分 |
截图哪里有这么复杂
public Bitmap GetScreenBmp(Rectangle rect)
{
Bitmap screenBmp = new Bitmap(rect.Width, rect.Height);
using (Graphics g = Graphics.FromImage(screenBmp))
{
g.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size);
Cursor.Current.Draw(g, new Rectangle(Cursor.Position.X, Cursor.Position.Y, 33, 33));
}
return screenBmp;
}
这就实现截屏了 |
|
楼主是用WIN API进行屏幕截屏的。
|
|
|
代码看不懂,或者有实现此功能更简单的代码吗? |
|
|
API相比CopyFromScreen有什么好处吗? |
|