Java 9 hdpi显示支持 - 多分辨率图像 - Windows中的名称约定和加载 [英] Java 9 hdpi display support - multi-resolution images - name convention and loading in Windows

查看:497
本文介绍了Java 9 hdpi显示支持 - 多分辨率图像 - Windows中的名称约定和加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据这些文章:





  • 然后创建并加载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]));


  • 使用 mrImage 对象就像任何其他图像一样。




关于命名约定没有任何自动:图像分辨率取自图像文件内容。


According to these articles:

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

Java 9 should support high DPI displays (automatic DPI scaling) in Swing. I have tested it on the last version of Java 9 Early Access + on Zulu 9 and it works and looks really great.

I was unable to solve only one thing - high resolution/retina image loading.

According to articles (links) above and below it should use an Apple name convention (@2x):

image.png, image@2x.png, image@3x.png, etc.

I tested these loading methods:

Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("something/image.png"));

and

ImageIO.read(getClass().getResource("/something/image.png"));

But none of these works (the only base image was loaded and blurred).

According to this:

https://netbeans.org/bugzilla/show_bug.cgi?id=239745

The first method should be promising.

Has anyone any experiences with this (using Swing or even JavaFX)? I'm not sure if I'm doing something wrong or this feature is not implemented to the current pre-release version of Java 9 sofar.


Update:

It should be possible:

http://openjdk.java.net/jeps/263

I've also tried following naming conventions (described here):

Windows : image.scale-<dpi-value>.png (image.scale-140.png)
Linux : image.java-scale2x.png
Mac : image@2x.png and image.java-scale2x.png

However, I cannot find any working solution or official information. I don't get it - hdpi displays are common today and Java applications look like s... on them.

解决方案

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.

这篇关于Java 9 hdpi显示支持 - 多分辨率图像 - Windows中的名称约定和加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆