C# 截屏
用System.Drawing.Graphics
的CopyFromScreen()
函数即可.
CopyFromScreen()
不是静态函数, 要实例化一个 Graphics
对象, 并且加载了图片才能使用
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
就是整个屏幕的截图了, 参数很容易懂, 就不写了.