Draw image with 1 pixel = 1 physical pixel with DPI scaling enabled

Hi,

I have a window with a global scale factor different than 1.0. This could for instance happen on a desktop with a DPI setting of more than 96DPI. This window has a subcomponent which displays an image. This image can be zoomed in and out, but if the zoom setting is 100%, then the image should be displayed with 1 image pixel = 1 display pixel, independent of the DPI setting.

Now, if you just apply a scale of 1 / getGlobalScaleFactor(), then the scale is correct but the alignment of the pixels is wrong, so every pixel of the image gets spread over 2×2 adjacent pixels on the screen, which slightly blurs the image.

Is it possible to figure out the exact physical screen bounds of a component? There are a lot of functions in Component and ComponentPeer but all of them seem to round the returned coordinates to integers.

--
Roeland

I doubt if it makes much sense to try to find a reliable way to do that - a window could be at an odd pixel offset, so even positioning your image carefully within it could end up wrong. And on Windows, the scale factor could easily be a non-integer number. Maybe question why it is that you think you need to do this in the first place, as modern graphics devices are constantly moving away from pixels being something that you deal with.

AFAIK windows always are at integer pixel positions. On Windows, Mac OS and Linux, the windows always are aligned on pixels, and on mobile devices apps run full-screen.

Our software is rendering software, and a lot of our users need to examine the image to see how much noise is present in the rendered image. To do that you need to have the image aligned on the pixel grid when displayed 1:1.

Another thing is, if you have icons for your user interface, to have them look good they must be aligned on the pixel grid, otherwise all the horizontal and vertical lines will be blurred. This is the case for both vector and bitmap formats.

--
Roeland

Anyway, as a workaround I can eliminate the blurring by setting the image resampling quality to low.

--
Roeland