[GiF] Working with Graphics on Windows in a pixel perfect way

pixel_perfect_2.gif

pixel_perfect.gif

14 Likes

news-congrads-kkluyshnik-02-04-19.jpg – you have earned Featured Contributor Badge 2015-11-02_10-07-11.png
Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

Thank you, Silvia!

There is another recent MMa.SE thread with important observations:

Please note the second bullet point in the “TL;DR” section of my answer there: it stresses an undesirable side effect of the current (version 13.0.0) mechanism of handling of ImageResolution by the system.

The problem is that on the Image rendering (“typesetting”) stage the Image option value (for example) ImageResolution -> 96 is first translated into the value of ImageSizeRaw option of GraphicsBox through multiplying ImageDimensions by the coefficient (72/96), and then ImageSizeRaw seemingly is rounded down by the FrontEnd before applying the hidden scale 96/72 on Windows. As the result, we don’t get the pixel-perfect rendering even for images with ImageResolution -> 96 (i.e. with resolution equal to the most common screen resolution on Windows systems 96 DPI), for which we should have pixel-perfect rendering naturally.

You can see how the translation happens by applying ToBoxes:

img = RandomImage[1, {110, 113}, ImageResolution -> 96]
Options[ToBoxes[img], ImageSizeRaw]

2 Likes

As a remedy, I suggest changing the ImageResolution handling mechanism: do not translate ImageResolution to ImageSizeRaw, but set appropriate Magnification instead:

Image[img, ImageResolution -> 72, Magnification -> 72/96]
Options@ToBoxes[%]

As you see from the screenshot, it allows avoiding the image size rounding and achieving pixel-perfect rendering of the image.

2 Likes

… seemingly is rounded down by the FrontEnd before applying the hidden scale 96/72 on Windows.

Indeed I saw trace of similar rounding behaviour when observing notebook size and cell-bracket. I think the whole pixel-perfect topic worth further investigations and clarifications.

1 Like