怎么得到屏幕的分辨率?

socg 2016-09-20 03:37:15
现在用的Win10系统,有系统级别的缩放,软件得知的是虚拟尺寸,绘制函数执行后由系统进行放大绘制到屏幕上,现在又回到老问题了,怎么得到屏幕的实际尺寸。

GetWindowImage、System.Windows.Forms.Screen.PrimaryScreen.Bounds都不能的到正确数值。

我的屏幕是 2880*1800,程序得到的是 1920*1200
...全文
711 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
socg 2016-10-09
  • 打赏
  • 举报
回复
a516018579:在我机器上确实不行,Win10 64位系统,你有没有调用开关之内函数?看我20楼回复。 chb345536638:我不管什么缩放,获得的DPI都是96 zhi_ai_yaya:固定值除非有官方的说明文档,否则不敢轻易信任,已经知道DPI是因机器而异了,至少我和oysy老兄是这样的。谁知道微软什么时候更新软件就不能用了
a516018579 2016-09-23
  • 打赏
  • 举报
回复
引用 23 楼 a516018579 的回复:
http://www.myexception.cn/winrt-metro/2021267.html
系统: win10 一周年 分辨率:3000x2000 系统缩放:200% 测试下没问题
引用 14 楼 socg 的回复:
[quote=引用 13 楼 socg 的回复:] [quote=引用 12 楼 xuzuning 的回复:] int cx = GetSystemMetrics( SM_CXSCREEN ); int cy = GetSystemMetrics( SM_CYSCREEN ); 不行吗?
等我试试[/quote] 不行,得到的还是虚拟尺寸[/quote] 我这里测试是OK的
a516018579 2016-09-23
  • 打赏
  • 举报
回复
http://www.myexception.cn/winrt-metro/2021267.html
我叫小菜菜 2016-09-23
  • 打赏
  • 举报
回复
MSDN的demodemodemodemodemodemodemo............

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

namespace SystemInfoBrowser
{
    public class SystemInfoBrowserForm : System.Windows.Forms.Form
    {
        private System.Windows.Forms.ListBox listBox1;
        private System.Windows.Forms.TextBox textBox1;        

        public SystemInfoBrowserForm()
	    {
            this.SuspendLayout();
            InitForm();

            // Add each property of the SystemInformation class to the list box.
            Type t = typeof(System.Windows.Forms.SystemInformation);            
            PropertyInfo[] pi = t.GetProperties();            
            for( int i=0; i<pi.Length; i++ )
                listBox1.Items.Add( pi[i].Name );            
            textBox1.Text = "The SystemInformation class has "+pi.Length.ToString()+" properties.\r\n";

            // Configure the list item selected handler for the list box to invoke a 
            // method that displays the value of each property.
            listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);
            this.ResumeLayout(false);
	    }
		
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Return if no list item is selected.
            if( listBox1.SelectedIndex == -1 ) return;
            // Get the property name from the list item.
            string propname = listBox1.Text;

            if( propname == "PowerStatus" )
            {
                // Cycle and display the values of each property of the PowerStatus property.
                textBox1.Text += "\r\nThe value of the PowerStatus property is:";                                
                Type t = typeof(System.Windows.Forms.PowerStatus);
                PropertyInfo[] pi = t.GetProperties();            
                for( int i=0; i<pi.Length; i++ )
                {
                    object propval = pi[i].GetValue(SystemInformation.PowerStatus, null);            
                    textBox1.Text += "\r\n    PowerStatus."+pi[i].Name+" is: "+propval.ToString();
                }
            }
            else
            {
                // Display the value of the selected property of the SystemInformation type.
                Type t = typeof(System.Windows.Forms.SystemInformation);
                PropertyInfo[] pi = t.GetProperties();            
                PropertyInfo prop = null;
                for( int i=0; i<pi.Length; i++ )
                    if( pi[i].Name == propname )
                    {
                        prop = pi[i];
                        break;           
                    }
                object propval = prop.GetValue(null, null);            
                textBox1.Text += "\r\nThe value of the "+propname+" property is: "+propval.ToString();
            }
        }

        private void InitForm()
        {
            // Initialize the form settings
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.textBox1 = new System.Windows.Forms.TextBox();            
            this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
            this.listBox1.Location = new System.Drawing.Point(8, 16);
            this.listBox1.Size = new System.Drawing.Size(172, 496);
            this.listBox1.TabIndex = 0;            
            this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Right)));
            this.textBox1.Location = new System.Drawing.Point(188, 16);
            this.textBox1.Multiline = true;
            this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;           
            this.textBox1.Size = new System.Drawing.Size(420, 496);
            this.textBox1.TabIndex = 1;            
            this.ClientSize = new System.Drawing.Size(616, 525);            
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.listBox1);            
            this.Text = "Select a SystemInformation property to get the value of";                   
        }

        [STAThread]
        static void Main() 
        {
            Application.Run(new SystemInfoBrowserForm());
        }
    }
}
-----结果分析 结果分析---------------------- 屏幕分辨率 1366 * 768 ---------------------- 放大125% The value of the WorkingArea property is: {X=0,Y=0,Width=1093,Height=574} - System.Windows.Forms.Screen.PrimaryScreen {Bounds = {X=0,Y=0,Width=1093,Height=614} WorkingArea = {X=0,Y=0,Width=0,Height=0} Primary = true DeviceName = "\\\\.\\DISPLAY1"} System.Windows.Forms.Screen + System.Windows.Forms.SystemInformation.WorkingArea {X = 0x00000000 Y = 0x00000000 Width = 0x00000445 Height = 0x0000023e} System.Drawing.Rectangle 说明:WorkingArea {X=0,Y=0,Width=1093,Height=574} 乘以125%恰好就是1366*728 --------------------- 放大100% The value of the WorkingArea property is: {X=0,Y=0,Width=1366,Height=728} + System.Windows.Forms.Screen.PrimaryScreen {Bounds = {X=0,Y=0,Width=1366,Height=768} WorkingArea = {X=0,Y=0,Width=0,Height=0} Primary = true DeviceName = "\\\\.\\DISPLAY1"} System.Windows.Forms.Screen + System.Windows.Forms.SystemInformation.WorkingArea {X = 0x00000000 Y = 0x00000000 Width = 0x00000556 Height = 0x000002d8} System.Drawing.Rectangle ----- 结论: 通过SystemInformation获取到的都是经过比例放大之后的计算结果值,所以只需要再找到放大比例参数,就可以计算出实际物理分辨率。 可以查找固定的值,比如DPI,比如IconSize,都是有固定值的,稍微换算一下应该可以计算出来。
飞天凤凰601 2016-09-23
  • 打赏
  • 举报
回复
引用 19 楼 chb345536638 的回复:
获取DPI

float dpiX, dpiY;
Graphics graphics = this.CreateGraphics();
dpiX = graphics.DpiX;
dpiY = graphics.DpiY;
96 DPI = 100% 120 DPI = 125% 144 DPI = 150% 192 DPI = 200%
呵呵,我在150%时,得到的dpi是96,我晕
socg 2016-09-22
  • 打赏
  • 举报
回复
看两个图




代码中包含System.Windows.SystemParameters.PrimaryScreenWidth 时,得到了正确的分辨率,尽管它在后面,感觉是.Net预读程序,发现有调用 SystemParameters 就会自动禁用系统缩放,我按F5继续运行,程序界面也显示没有启用缩放
  • 打赏
  • 举报
回复
获取DPI

float dpiX, dpiY;
Graphics graphics = this.CreateGraphics();
dpiX = graphics.DpiX;
dpiY = graphics.DpiY;
96 DPI = 100% 120 DPI = 125% 144 DPI = 150% 192 DPI = 200%
飞天凤凰601 2016-09-22
  • 打赏
  • 举报
回复
对了,谁知道怎么得到系统这个放大或缩小的参数?
飞天凤凰601 2016-09-22
  • 打赏
  • 举报
回复
引用 16 楼 luxingcun 的回复:
//获取PC屏幕的宽
int width = Screen.PrimaryScreen.Bounds.Width;
//获取PC屏幕的高
int height = Screen.PrimaryScreen.Bounds.Height;



呵呵,你得考虑,在设置分辨率哪里的,“放大”或”缩小“文本这个选项!这个也是得不到真正分辨率的原因,我也找了好久,没办法
只有在100%时,是准确的!
luxingcun 2016-09-22
  • 打赏
  • 举报
回复
//获取PC屏幕的宽 int width = Screen.PrimaryScreen.Bounds.Width; //获取PC屏幕的高 int height = Screen.PrimaryScreen.Bounds.Height;
慧眼识狗熊 2016-09-22
  • 打赏
  • 举报
回复
SystemParameters.WorkArea;//除任务栏外工作区大小 SystemParameters.PrimaryScreenWidth;//屏幕宽 SystemParameters.PrimaryScreenHeight;
socg 2016-09-21
  • 打赏
  • 举报
回复
引用 13 楼 socg 的回复:
[quote=引用 12 楼 xuzuning 的回复:] int cx = GetSystemMetrics( SM_CXSCREEN ); int cy = GetSystemMetrics( SM_CYSCREEN ); 不行吗?
等我试试[/quote] 不行,得到的还是虚拟尺寸
socg 2016-09-21
  • 打赏
  • 举报
回复
引用 12 楼 xuzuning 的回复:
int cx = GetSystemMetrics( SM_CXSCREEN ); int cy = GetSystemMetrics( SM_CYSCREEN ); 不行吗?
等我试试
xuzuning 2016-09-21
  • 打赏
  • 举报
回复
int cx = GetSystemMetrics( SM_CXSCREEN ); int cy = GetSystemMetrics( SM_CYSCREEN ); 不行吗?
socg 2016-09-21
  • 打赏
  • 举报
回复
引用 9 楼 wenyiyi 的回复:
这个需要通过windows的API 来获取吧
不好意思,错了,是 GetWindowRect
socg 2016-09-21
  • 打赏
  • 举报
回复
引用 9 楼 wenyiyi 的回复:
这个需要通过windows的API 来获取吧
GetWindowImage就是API,传入桌面句柄,得到的还是虚拟分辨率
wenyiyi 2016-09-20
  • 打赏
  • 举报
回复
这个需要通过windows的API 来获取吧
socg 2016-09-20
  • 打赏
  • 举报
回复
没有使用Win10的程序员吗?
socg 2016-09-20
  • 打赏
  • 举报
回复
win10有底层缩放的,
引用 6 楼 sp1234 的回复:
他要得到的显卡驱动支持的最大分辨率。lz 的名词儿误导了你。 [quote=引用 5 楼 qq_17486399 的回复:] [quote=引用 4 楼 qq_17486399 的回复:] 剩下的20个像素是菜单栏。
气蒙了,剩下40.就是这个东西[/quote][/quote] 我要得到的就是当前分辨率
  • 打赏
  • 举报
回复
他要得到的显卡驱动支持的最大分辨率。lz 的名词儿误导了你。
引用 5 楼 qq_17486399 的回复:
[quote=引用 4 楼 qq_17486399 的回复:] 剩下的20个像素是菜单栏。
气蒙了,剩下40.就是这个东西[/quote]
加载更多回复(5)

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧