所有 Windows PC 显示器上的每英寸像素数是否为标准?(LogPixelsX) 在 GetDeviceCaps WinAPI 调用中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/645352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is the number of Pixels per Inch standard on all Windows PC displays? (LogPixelsX) in the GetDeviceCaps WinAPI call
提问by Clay Nichols
By Windows PC displays, I am not referring to Windows CE, or handhelds, etc.
对于 Windows PC 显示器,我指的不是 Windows CE 或手持设备等。
Clarification
Some folks below mistakenly thought I was asking what the DPI (dots per inch) was on monitors. What I'm asking for is the value for LogPixelsX in the GetCapsAPI call :
澄清
下面的一些人错误地认为我在问显示器上的 DPI(每英寸点数)是多少。我要的是GetCapsAPI 调用中LogPixelsX 的值:
LOGPIXELSXNumber of pixels per logical inch along the screen width.
LOGPIXELSX沿屏幕宽度每逻辑英寸的像素数。
In the examples I've seen, it's set to 88, regardlessof the screen DPI. Seems to be a Magic Number sort of constant.
在我看到的示例中,它设置为 88,而与屏幕 DPI无关。似乎是一个神奇的数字类型的常数。
In a related QuestionI'm using GetDeviceCaps to calculate current Screen Font DPI. The code samples I found all have:
在一个相关的问题中,我使用 GetDeviceCaps 来计算当前的屏幕字体 DPI。我发现的代码示例都有:
Const LOGPIXELSX = 88
常量 LOGPIXELSX = 88
Is this universally the same for all monitors (even widescreen vs regular monitors)? And if not, how do I find it for the current display. (MSDN indicates that it's the same for all monitors on a particularcomputer.
对于所有显示器(即使是宽屏显示器还是普通显示器),这是否普遍相同?如果没有,我如何为当前显示找到它。(MSDN 表明它对于特定计算机上的所有显示器都是相同的。
In a system with multiple display monitors, this value is the same for all monitors.
在具有多个显示监视器的系统中,该值对于所有监视器都是相同的。
回答by Mark Ransom
To answer your clarification of the question:
回答您对问题的澄清:
LOGPIXELSX is the parameter you pass to GetDeviceCaps to get the current monitor resolution (technically the horizontal resolution, but all modern displays have equal horizontal and vertical resolution). Yes, it is always 88 - if you wanted to get a different value from GetDeviceCaps, you'd pass in a different value. For example, to get the number of bits per pixel, you'd pass the BITSPIXEL constant which is 12. These magic constants are defined in the Windows API file WINGDI.h.
LOGPIXELSX 是您传递给 GetDeviceCaps 以获取当前显示器分辨率(技术上为水平分辨率,但所有现代显示器具有相同的水平和垂直分辨率)的参数。是的,它始终是 88 - 如果您想从 GetDeviceCaps 获得不同的值,您可以传入不同的值。例如,要获得每个像素的位数,您需要传递 BITSPIXEL 常数,即 12。这些魔法常数在 Windows API 文件 WINGDI.h 中定义。
The note in MSDN is referring not to the parameter, but the returned value.
MSDN 中的注释不是指参数,而是指返回值。
回答by Mark Ransom
Windows will always have 96 DPI for the resolution, unless you change it in the display settings. On XP, you find it in the Advanced dialog under Display Properties->Settings; I don't know where it's found in other versions of Windows.
Windows 的分辨率始终为 96 DPI,除非您在显示设置中更改它。在 XP 上,您可以在“显示属性”->“设置”下的“高级”对话框中找到它;我不知道它在其他版本的 Windows 中的位置。
You are correct that GetDeviceCaps(LOGPIXELSX) will return the DPI, except for one little caveat. Starting with Vista, Windows might lie to you about your actual configured resolution. You need to make your application DPI-aware to get a true picture of the configuration. Here's a Microsoft page providing some details, with special emphasis on changes coming in Windows 7.
您是正确的 GetDeviceCaps(LOGPIXELSX) 将返回 DPI,除了一个小警告。从 Vista 开始,Windows 可能会就您的实际配置分辨率向您撒谎。您需要使您的应用程序具有 DPI 感知能力,以了解配置的真实情况。这是一个 Microsoft 页面,提供了一些详细信息,特别强调了 Windows 7 中的变化。
http://msdn.microsoft.com/en-us/library/dd464659(VS.85).aspx
http://msdn.microsoft.com/en-us/library/dd464659(VS.85).aspx
And another link:
另一个链接:
http://msdn.microsoft.com/en-us/library/ms701681(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms701681(VS.85).aspx
回答by Nick
See SetProcessDPIAware()(for Vista) and GetDeviceCaps(...)to get the DPI.
请参阅SetProcessDPIAware()(对于 Vista)和GetDeviceCaps(...)以获取 DPI。
XP has 96 or 120 dpi. Vista actually has a slider to adjust through a "continuum" of DPI settings. On Vista, the DWM takes care of scaling your apps unless you explicitly call out that you are DPI-aware. For XP you should plan for both 96 and 120.
XP 有 96 或 120 dpi。Vista 实际上有一个滑块可以通过 DPI 设置的“连续体”进行调整。在 Vista 上,DWM 负责扩展您的应用程序,除非您明确指出您是 DPI 感知的。对于 XP,您应该同时计划 96 和 120。
回答by Mohit Puri
For the case of image,image resolution(DPIX,DPIY) is to be taken other constant monitor resolution.twips to pixels convertion for image dpi is done as:
对于图像,图像分辨率(DPIX,DPIY)将采用其他恒定的显示器分辨率。为图像 dpi 将像素转换为 twips 为:
public struct RECT_TAG
{
public int iLeft;
public int iTop;
public int iHeight;
public int iWidth;
}
public static RECT_TAG ConvertTwipsToPixels(RECT_TAG pobjRect, int plXDPI, int plYDPI)
{
pobjRect.iLeft = pobjRect.iLeft * plXDPI / 1440;
pobjRect.iTop = pobjRect.iTop * plYDPI / 1440;
pobjRect.iWidth = pobjRect.iWidth * plXDPI / 1440;
pobjRect.iHeight = pobjRect.iHeight * plYDPI / 1440;
return pobjRect;
}
回答by dustyburwell
The two standard DPI settings in Windows are 96 dpi (Normal size) and 120 dpi (Large size) I'm sure there's a Win32 call for getting at this setting, but I'm not sure where to direct you for it. MSDN may have your answer.
Windows 中的两个标准 DPI 设置是 96 dpi(正常尺寸)和 120 dpi(大尺寸)我确定有一个 Win32 调用来获取此设置,但我不确定将您引向何处。MSDN 可能有你的答案。
edit:I should clarify that by Windows I mean Windows XP
编辑:我应该澄清一下,Windows 我的意思是 Windows XP