简体   繁体   English

像素在显示器上是不是正方形?

[英]Are pixels ever not a square on a monitor?

I'm working on making my application DPI sensitive using this MSDN guide where the technique for scaling uses X and Y logical pixels from a device context. 我正在努力使用这个MSDN指南使我的应用程序DPI敏感,其中缩放技术使用来自设备上下文的X和Y逻辑像素。

int _dpiX = 96, _pdiY = 96;   
HDC hdc = GetDC(NULL);
if (hdc)
{
    _dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
    _dpiY = GetDeviceCaps(hdc, LOGPIXELSY);
    ReleaseDC(NULL, hdc);
}

Then you can scale X and Y coordinates using 然后,您可以使用缩放X和Y坐标

int ScaleX(int x) { return MulDiv(x, _dpiX, 96); }
int ScaleY(int y) { return MulDiv(y, _dpiY, 96); }

Is there ever a situation where GetDeviceCaps(hdc, LOGPIXELSX) and GetDeviceCaps(hdc, LOGPIXELSY) would return different numbers for a monitor. 是否存在GetDeviceCaps(hdc, LOGPIXELSX)GetDeviceCaps(hdc, LOGPIXELSY)为监视器返回不同数字的情况。 The only device I'm really concerned about is a monitor so do I need to have separate ScaleX(int x) and ScaleY(int y) functions? 我真正关心的唯一设备是监视器,所以我需要有单独的ScaleX(int x)ScaleY(int y)函数吗? Could I use just one Scale(int px) function? 我可以只使用一个Scale(int px)函数吗? Would there be a downside to doing this? 这样做会有不利之处吗?

Thanks in advance for the help. 在此先感谢您的帮助。

It is theoretically possible, but I don't know of any recent monitor that uses non-square pixels. 这在理论上是可行的,但我不知道最近使用非方形像素的显示器。 There are so many advantages to square pixels, and so much existing software assumes square pixels, that it seems unlikely for a mainstream monitor to come out with a non-square pixel mode. 方形像素有很多优点,而且现有的软件都采用方形像素,主流显示器似乎不太可能采用非方形像素模式。

In many cases, if you did have a monitor with non-square pixels, you probably could apply a transform to make it appear as though it has square pixels (eg, by setting the mapping mode). 在许多情况下,如果你确实有与非方形像素监视器,你也许可以应用转换,使其看起来好像它有方形像素(例如,通过设置映射模式)。

That said, it is common for printers to have non-square device units. 也就是说, 打印机通常使用非方形设备单元。 Many of them have a much higher resolution in one dimension than in the other. 他们中的许多人在一个维度上具有比在另一个维度中更高的分辨率。 Some drivers make this resolution available to the caller. 某些驱动程序使调用者可以使用此解决方案。 Others will make it appear as though it has square pixels. 其他人会让它看起来好像有正方形像素。 If you ever want to re-use your code for printing, I'd advise you to not conflate your horizontal and vertical scaling. 如果您想重新使用代码进行打印,我建议您不要混淆水平和垂直缩放。

Hardware pixels of LCD panels are always square. LCD面板的硬件像素始终是方形的。 Using CRT, you can have rectangular square, like using 320x200 or 320x400 resolution on 4:3 monitor (these resolution were actualy used). 使用CRT,您可以使用矩形正方形,例如在4:3监视器上使用320x200320x400分辨率(这些分辨率是实际使用的)。 On LCD you can get rectangular pixels by using non-native resolution on monitor - widescreen resolution on 5:4 monitor and vice versa. 在LCD上,您可以通过在显示器上使用非原生分辨率获得矩形像素 - 在5:4显示器上使用宽屏分辨率,反之亦然。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM