Thomas S. Thomas S. - 1 year ago 110
Java Question

How to correctly scale images on hi-res-screens

Our SWT-based Java application automatically uses the default font-size of the operating system and that to derive other fonts. Hence, the texts of the GUI look fine on hi-res-screens (e.g. 2880 x 1620 with Windows 8 being configured as "Larger" in Control Panel > Appearance and Personalization > Display). Unfortunately, the images are not scaled, so, e.g., tool bar buttons appear too small.

On OS X the hi-res-screen handling seems easy: the virtual resolution is just half of the size, but how to do the scaling on Windows which seems to allow non-integer scaling factors? How to detect when to scale and when not?

It looks like this SWT issue covers a similar problem.

Answer Source

Have a look at Neon (4.6) M6 - New and Noteworthy, the milestone release contains some automatic scaling for images (e.g. for toolbar).

SWT provides resolution-based auto-scaling

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:


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.

Or maybe this helps, in Eclipse Mars API for high resolution was added

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:

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 for high-DPI monitor support

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download