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

标签 java swt

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

在 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.

enter image description here

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.

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

关于java - 如何在高分辨率屏幕上正确缩放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29211861/

相关文章:

java - Hibernate session.getTransaction().begin() 与 session.beginTransaction() 之间的区别

java - 关于线程中止和死锁的问题 - volatile 关键字

java - Spring JDBCTemplate 与 Hikari 数据源批量更新异步行为

从 SWT 3 切换到 SWT 4 时,JAVA SWT KeyDown 事件触发了 3 次而不是 1 次

java - 将像素从一张图像复制到另一张图像

java - 运行 Java 解释器以将控制台输出作为字符串返回

java - 编写一个程序来搜索数组以找到第一个奇数

Java SWT 从按钮刷新多个 Shell

java - CTabFolder布局控件不渲染

java - SWT 浏览器内部链接不适用于 IE6