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.
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
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. 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? Could I use just one Scale(int px)
function? Would there be a downside to doing this?
Thanks in advance for the help.
A pixel (short for “picture element”) is the smallest editable component of a raster image. Pixels are usually square (except in some digital video formats) and are arranged in a grid of horizontal rows and vertical columns.
Pixels need not be square, but the typical deviation from square is rectangular. The way an abstract pixel is actually realized on a physical display device can vary considerably depending on the device technology.
In the sense of imaging theory, in which "pixel" is meant to mean a sample of an image, no, they are not circular - they're supposed to be treated in that context as point samples, and therefore dimensionless.
Pixels are commonly square because squares fit together without leaving gaps, have sides of equal length and can be mapped to a grid with two axes – horizontal and vertical. If pixels were circles, there would be gaps when surrounded by neighbouring circles – not ideal for creating smooth images on a screen.
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 (e.g., 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. Using CRT, you can have rectangular square, like using 320x200
or 320x400
resolution on 4:3
monitor (these resolution were actualy used). On LCD you can get rectangular pixels by using non-native resolution on monitor - widescreen resolution on 5:4
monitor and vice versa.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With