【问题标题】:How can I take a picture from screen?如何从屏幕上拍照?
【发布时间】:2011-04-19 03:33:00
【问题描述】:

我想编写一个程序,向其他人显示一台 PC 的屏幕......类似于演示系统。如何从当前屏幕拍照?

【问题讨论】:

    标签: c# screen screen-capture


    【解决方案1】:

    .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
    

    【讨论】:

    • 感谢您的帮助...还有其他方法可以加快速度吗?因为我的项目从屏幕复制应该很慢...
    • GDI+ 方法在任何指标上都不是世界上最快的。你打算用这个做什么?
    猜你喜欢
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    相关资源
    最近更新 更多