Windows屏幕截图可缩放 [英] Windows screenshot with scaling

查看:118
本文介绍了Windows屏幕截图可缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取Windows 10计算机上每个屏幕的屏幕截图. 我的系统有2个监视器,这些监视器具有多个DPI.

I am trying to take screenshots of every screen on my windows 10 machine. My system has 2 monitors which are of multiple DPIs.

  • 我的主显示器的比例和布局"设置为200%.
  • 我的中学 将比例和布局"设置为100%.
  • My primary monitor has "scale and layout" set to 200%.
  • My secondary has "scale and layout" set to 100%.

我正在尝试使用C#拍摄每个监视器的屏幕截图. 但是我的缩放监视器报告了错误的坐标: 一切都减半. 结果,主监视器的屏幕截图仅为屏幕区域的1/4(宽度/2,高度/2).

I am trying to use C# to take a screenshot of every single monitor. However my scaled monitor is reporting the wrong coordinates: Everything is halved. As a result, the primary monitor's screenshot is only 1/4th of the screen area (width/2,height/2).

这是我的代码:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;

namespace CsSourceClient
{
    class Program
    {
        static void Main(string[] args)
        {
            Screen[] screens;
            screens = Screen.AllScreens;


            int i = 0;

            foreach (var screen in System.Windows.Forms.Screen.AllScreens)
            {
                var savePath = "monitor" + i+".jpg";
                var x = screen.Bounds.Location.X;
                var y = screen.Bounds.Location.Y;
                var w = screen.Bounds.Width;
                var h = screen.Bounds.Height;
                Console.Out.WriteLine("Monitor: " + i + " extents:" + x + "," + y + " " + w + "," + h);
                using (Bitmap bmp = new Bitmap(w, h))
                {
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        g.CopyFromScreen(x, y, 0, 0, bmp.Size);
                    }

                    bmp.Save(savePath, ImageFormat.Jpeg);
                    Console.Out.WriteLine("saved: " + savePath);
                }
                i++;
            }



        }
    }
}

PS:根据清单文件中设置的"dpiaware",我得到不同的值:

PS: I get different values based on what I set "dpiaware" in the manifest file: https://social.msdn.microsoft.com/Forums/en-US/054c1d49-9f24-4617-aa83-9bc4f1bb4a5d/use-appmanifest-file-to-make-winforms-application-dpi-aware?forum=vbgeneral

如果我未设置dpiaware,则主监视器的边界减半(裁剪出屏幕的3/4英寸). 如果将dpiaware设置为true,则辅助监视器的边界将加倍(在屏幕截图中留有较大的黑色区域).

If I don't set dpiaware, then the primary monitor's bounds get halved (cropping out 3/4ths of the screen). If I set dpiaware to true, then the secondary monitor's bounds get doubled (leaving big black areas in the screenshot).

推荐答案

如注释中所述,解决方案是将app.manifest dpiAware标记设置为"true/pm" .效果与仅将其设置为true有所不同.

As mentioned in the comments, the solution is to set the app.manifest dpiAware tag to "true/pm". The effect is different than just setting it to true.

<application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
    </windowsSettings>
  </application>

这篇关于Windows屏幕截图可缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆