Message Boards Message Boards

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

enter image description here

enter image description here

POSTED BY: Silvia Hao
4 Replies
Posted 3 years ago

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]

screenshot

POSTED BY: Alexey Popkov
Posted 3 years ago

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[%]

screenshot2

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

POSTED BY: Alexey Popkov

... 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.

POSTED BY: Silvia Hao

enter image description here -- you have earned Featured Contributor Badge enter image description here 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!

POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract