C# 截屏

System.Drawing.GraphicsCopyFromScreen()函数即可.

CopyFromScreen() 不是静态函数, 要实例化一个 Graphics 对象, 并且加载了图片才能使用

1
2
3
4
5
6
7
8
9
	public Bitmap CopyScreen()
	{
	    Rectangle tScreenRect = new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
	    Bitmap bitmap = new Bitmap(tScreenRect.Width, tScreenRect.Height);
	    Graphics graphics = Graphics.FromImage(bitmap);
	    graphics.CopyFromScreen(0, 0, 0, 0, tScreenRect.Size);
	    graphics.DrawImage(bitmap, 0, 0, tScreenRect, GraphicsUnit.Pixel);
	    return bitmap;
	}

这里的bitmap就是整个屏幕的截图了, 参数很容易懂, 就不写了.