-
Enhancement
-
Resolution: Unresolved
-
P3
-
9
-
generic
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
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
- relates to
-
JDK-8052409 Support "scale" naming convention for high-resolution images on Windows
- Open
-
JDK-8011140 [macosx] Support automatic @2x images loading on Mac OS X
- Closed