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

Unified way to load resolution variants for multi-resolution image

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 9
    • client-libs

       Different OSes use different "scale" naming convention for high-resolution images:
       Mac OS X: image.ext, image@2x.ext
       Windows: image.scale-100.ext, image.scale-140.ext, image.scale-180.ext

      It is better to have a unified way to load high resolution images in JDK.

      The proposal is to add a method to the Toolkit class that allows load images with the given scale factors:
        public abstract Image getImage(String[] names, float[] scaleFactors);

      The use case is:
              Image multiResolutionImage = Toolkit.getDefaultToolkit().getImage((
                      new String[]{"duke1.png", "duke2.png"}, new float[]{1, 2});

      Mac OS X naming convention:
              Image multiResolutionImage = Toolkit.getDefaultToolkit().getImage((
                      new String[]{"duke.png", "duke@2x.png"}, new float[]{1, 2});

      Windows naming convention:
              Image multiResolutionImage = Toolkit.getDefaultToolkit().getImage((
                      new String[]{"duke.scale-100.png", "duke.scale-140.png", "duke.scale-180.png"}, new float[]{1.0f, 1.4f, 1.8f});



      The loaded multi-resolution image can be used in icon
        new ImageIcon(multiResolutionImage) // resolution variant is used according to the display scale factor
      or be drawn by Graphics
        g.drawImage(multiResolutionImage, 0, 0, null) // resolution variant is used according to the current transforms and the display scale factor

            Unassigned Unassigned
            alexsch Alexandr Scherbatiy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: