【问题标题】:.NET 4.0 Graphics library - How can I capture the "whole" screen?.NET 4.0 图形库 - 如何捕获“整个”屏幕?
【发布时间】:2019-06-23 18:14:05
【问题描述】:

我正在编写一个小应用程序,每隔 X 秒截取一次屏幕截图,但我遇到了一个小而烦人的障碍。以这张图片为例:

使用 Windows 7 上的默认“打印屏幕”功能捕获的屏幕

如果我尝试使用默认的 .NET 4 图形库截取相同的屏幕截图,则圆圈区域不会显示。 Visual Studio 选项卡式菜单和我不记得的其他一些应用程序也是如此。图像的其余部分都很好。

这是我正在使用的代码。我可能会搞砸一些事情,但我无法为我的生活弄清楚。任何帮助将不胜感激:

memoryImage = new Bitmap(resolution.Width, resolution.Height);
Size s = new Size(memoryImage.Width, memoryImage.Height);
// Create graphics 
Console.WriteLine("Creating Graphics...");
Console.WriteLine();
Graphics memoryGraphics = Graphics.FromImage(memoryImage);

// Copy data from screen 
Console.WriteLine("Copying data from screen...");
Console.WriteLine();
memoryGraphics.CopyFromScreen(0, 0, 0, 0, s);

【问题讨论】:

    标签: c# .net-4.0


    【解决方案1】:

    此测试在我的配置(Windows 10、VS 2015)上正确保存整个屏幕 =>

    Rectangle screenBounds = Screen.GetBounds(System.Drawing.Point.Empty);
    using (Bitmap bitmap = new Bitmap(screenBounds.Width, screenBounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
    {
        using (Graphics g = Graphics.FromImage(bitmap))
        {                       
            g.CopyFromScreen(0, 0, 0, 0, bitmap.Size, CopyPixelOperation.SourceCopy);
        }
        bitmap.Save("e:\\ScreenCopy.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
    }
    

    【讨论】:

      猜你喜欢
      • 2012-04-19
      • 2017-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-23
      • 1970-01-01
      相关资源
      最近更新 更多