C# 在 Windows 中启用缩放功能捕获屏幕截图

问题描述 投票:0回答:4

我刚刚开始编写这个小型 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);
c# windows zooming screenshot imaging
4个回答
1
投票

所以,这个问题最终被我的朋友解决了,但由于他不住在这里,我会自己写答案。

溶剂实际上在app.manifest中,这一行完全解决了问题:

< dpiAware >真实< /dpiAware >


0
投票

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

当您使用缩放屏幕或多台显示器时,您必须自己定义这一点。

Screen.PrimaryScreen.Bounds.Width
,因为这个常数定义了屏幕的尺寸/屏幕的分辨率。

希望这有帮助。


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

并获取屏幕截图


0
投票

我制作了一个关于它的视频并找到了问题的解决方案(YouTube):
https://youtu.be/FUmZi8JDSLU?si=PRGfeJycKFyzaOdt

代码在这里(GitHub): https://github.com/WhizTechh/TakeScreenshotWinForms

这将解决左上角屏幕部分的问题。
有点太晚了,但对于那些需要它的人,我正在提供它。

© www.soinside.com 2019 - 2024. All rights reserved.