Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8209968

Image size sometimes off by 1 when scaling down images with preserveRatio true

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • jfx11, 9
    • jfx12
    • javafx

    Description

      When an Image is loaded using new Image() you have the option of having it scaled down while preserving the aspect ratio. However, the calculated dimensions are sometimes off by 1 pixel for images that have the exact same aspect ratio due to a rounding error.

      A list of input sizes I tried and their resulting size when asking for Images to have a requested width and height of 108x108 pixels while preserving aspect ratio:

       width=800,height=1200 --> resulted in Image of 72.0x108.0
       width=1000,height=1500 --> resulted in Image of 72.0x107.0
       width=1400,height=2100 --> resulted in Image of 72.0x108.0
       width=1440,height=2160 --> resulted in Image of 72.0x108.0
       width=2000,height=3000 --> resulted in Image of 72.0x107.0

      When debugging this for one of the cases that resulted in a y dimension of 107, the intermediate value was calculated for sourceHeight * scale was 107.99999, however the code casts this directly to an int and you get 107

      Attachments

        Activity

          People

            jhendrikx John Hendrikx
            jhendrikx John Hendrikx
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: