1

我刚刚开始编写这个小 C# 程序,目的无关紧要。现在它尝试制作整个屏幕的屏幕截图,它成功了......有点......

问题是我正在以 200% 缩放运行 Windows(不,我的视力不差),当我运行此代码时,我只保存了 1/4 的屏幕(左上部分),而不是预期的全部. 我非常确定这与 200% 缩放有关,我想问是否有人可以提出解决方法,以便它实际上捕获我的整个屏幕。这是代码:

        string savePath = @"C:\Users\eltaro\Desktop\ScreenShot "+DateTime.Now.ToString("yyyy-MM-dd")+" at "+DateTime.Now.ToString("HH.mm")+".bmp";
        bmpImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
        gfxScreenshot = Graphics.FromImage(bmpImage);
        gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0,
            Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
        bmpImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Bmp);
4

3 回答 3

1

So, this problem ended up being solved by my friend, but since he does not dwell here, I will write the answer myself.

The solvent was actually in app.manifest, this one line solves the problem entirely:

< dpiAware >true< /dpiAware >

于 2013-09-14T15:07:39.210 回答
0

来自 MSDN:Graphics.CopyFromScreen(Int32, Int32, Int32, Int32, Size):执行从屏幕到图形绘图表面的对应于像素矩形的颜色数据的位块传输。”

当您使用缩放屏幕或多个显示器时,您必须自己定义它。Screen.PrimaryScreen.Bounds.Width, 因为这个常数定义了屏幕的大小/屏幕的分辨率。

希望这可以帮助。

于 2013-09-12T09:16:01.307 回答
0

设置

Screen.WorkingArea
Bitmap bmpImage = new Bitmap(Screen.AllScreens[0].WorkingArea.Height, Screen.AllScreens[0].WorkingArea.Width, PixelFormat.Format32bppArgb);

http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.workingarea.aspx

并截图

于 2013-09-12T09:16:45.850 回答