Java 9 hdpi display support - multi-resolution images - name convention and loading in Windows

前端 未结 1 2032
遇见更好的自我
遇见更好的自我 2020-12-15 16:07

According to these articles:

http://news.kynosarges.org/2015/06/29/javafx-dpi-scaling-fixed
https://twitter.com/michaelsamarin/status/7292347792

相关标签:
1条回答
  • 2020-12-15 16:23

    As part of HiDPI support, Java 9 introduced multi-resolution support via the java.awt.MultiResolutionImage interface and the java.awt.image.AbstractMultiResolutionImage et al classes. Although they're supported in Swing, there have been bugs and misunderstandings in this area.

    Those don't exist in earlier Java versions, so if you want your users to be able to continue to run with earlier runtimes, you're going to have to write code to use regular Image classes when running on earlier JREs.

    To use those, you do something like:

    • Start with a set of images are different resolutions:

    • Then create and load the MultiResolutionImage:

      List<Image> imgList = new ArrayList<Image>();
      imgList.add(ImageIO.read(new File("320px-Eagle.jpg"));
      imgList.add(ImageIO.read(new File("800px-Eagle.jpg"));
      imgList.add(ImageIO.read(new File("1024px-Eagle.jpg"));
      imgList.add(ImageIO.read(new File("1280px-Eagle.jpg"));
      imgList.add(ImageIO.read(new File("Eagle.jpg"));
      MultiResolutionImage mrImage = new BaseMultiResolutionImage(imgList.toArray(new Image[0]));
      
    • The use the mrImage object just like any other image.

    There's nothing automatic about the naming convention: The image resolution is taken from the image file contents.

    0 讨论(0)
提交回复
热议问题