【发布时间】:2011-04-19 03:33:00
【问题描述】:
我想编写一个程序,向其他人显示一台 PC 的屏幕......类似于演示系统。如何从当前屏幕拍照?
【问题讨论】:
标签: c# screen screen-capture
我想编写一个程序,向其他人显示一台 PC 的屏幕......类似于演示系统。如何从当前屏幕拍照?
【问题讨论】:
标签: c# screen screen-capture
.NET 通过 Screen (System.Windows.Forms) 类公开此功能。
// the surface that we are focusing upon
Rectangle rect = new Rectangle();
// capture all screens in Windows
foreach (Screen screen in Screen.AllScreens)
{
// increase the Rectangle to accommodate the bounds of all screens
rect = Rectangle.Union(rect, screen.Bounds);
}
// create a new image that will store the capture
Bitmap bitmap = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(bitmap))
{
// use GDI+ to copy the contents of the screen into the bitmap
g.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy);
}
// bitmap now has the screen capture
【讨论】: