如何在高分辨率屏幕上正确缩放图像

How to correctly scale images on hi-res-screens

我们基于 SWT 的 Java 应用程序自动使用操作系统的默认字体大小,并派生其他字体。因此,GUI 的文本在高分辨率屏幕上看起来很好(例如 2880 x 1620,Windows 8 在控制面板 > 外观和个性化 > 显示中配置为 "Larger")。不幸的是,图像未缩放,因此,例如,工具栏按钮显得太小了。

在 OS X 上处理高分辨率屏幕似乎很容易:虚拟分辨率只有一半大小,但是如何在 Windows 上进行缩放这似乎允许非-整数比例因子?如何检测何时缩放何时不缩放?

更新 看起来 this SWT issue 涵盖了类似的问题。

查看 Neon (4.6) M6 - New and Noteworthy,里程碑版本包含一些图像自动缩放(例如工具栏)。

SWT 提供基于分辨率的自动缩放

SWT now automatically scales images on high-DPI monitors on Windows and Linux, similar to the Mac's Retina support on OS X. In the absence of high-resolution images, SWT will auto-scale the available images to ensure that SWT-based applications like Eclipse are scaled proportionately to the resolution of the monitor.

This feature can be disabled on Windows and GTK by setting this VM argument to false in eclipse.ini or on the command line after -vmargs:

-Dswt.enable.autoScale=false

Auto-scaling cannot be disabled on the Mac as it is provided by the OS.

Caveats: We're aware that some scaled images look bad at scale factors less than 200%. This will be improved in M7. Furthermore, we're working on support for high-DPI images in Platform UI, so that plug-in providers can add high-DPI icons without doing any code changes.



或者这可能有帮助,在 Eclipse Mars API 中添加了高分辨率

New APIs have been added to provide support for rendering high-resolution images on high-DPI monitors. Two constructors have been added to the Image class. They accept image-provider callbacks that allow clients to supply resolution-dependent versions of images:

public interface ImageDataProvider {
  public ImageData getImageData (int zoom);
}
public interface ImageFileNameProvider {
  public String getImagePath (int zoom);
}

Depending on the user's monitor configuration, SWT will request images with the corresponding zoom level. Here's an example that displays 3 original images, followed by variants whose resolution changes depending your monitor's resolution: Snippet367.java.

Note that this is just the first step to support high-resolution images in SWT and Eclipse-based applications. Work is underway to adopt the new APIs in the platform. Futhermore, more work in SWT is required to properly support drawing into high-resolution images via GC.

APIs 高 DPI 监视器支持
http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2FwhatsNew%2Fplatform_isv_whatsnew.html