简体   繁体   English

.NET 4.0图形库 - 如何捕获“整个”屏幕?

[英].NET 4.0 Graphics library - How can I capture the “whole” screen?

I'm coding a small app to take a screenshot every X seconds and I've ran into a small but annoying roadblock. 我正在编写一个小应用程序,每隔X秒拍一次屏幕截图,我遇到了一个小而烦人的障碍。 Take this image, for example: 拍这张照片,例如:

Screen captured using the default 'Print Screen' function on Windows 7 使用Windows 7上的默认“打印屏幕”功能捕获屏幕 在此输入图像描述

If I try to take the same screenshot by using the default .NET 4 Graphics library, the circled area doesn't show up. 如果我尝试使用默认的.NET 4图形库拍摄相同的屏幕截图,则圆圈区域不会显示。 Same happens with Visual Studio tabbed menus and some other apps I can't remember. Visual Studio选项卡式菜单和其他一些我不记得的应用程序也是如此。 The rest of the image comes out fine, tho. 图像的其余部分很好,所以。

This is the code I'm using. 这是我正在使用的代码。 I might be screwing something up but I can't figure it for the life of me. 我可能会搞砸了一些事情,但我无法想象我的生活。 Any help would be appreciated: 任何帮助,将不胜感激:

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);

This test saves correctly the whole screen on my configuration (Windows 10, VS 2015) => 此测试可以在我的配置(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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM