JFormDesigner / FlatLaf

FlatLaf - Swing Look and Feel (with Darcula/IntelliJ themes support)
https://www.formdev.com/flatlaf/
Apache License 2.0
3.31k stars 265 forks source link

Enable image interpolation bilinear by default #260

Open asomolinos opened 3 years ago

asomolinos commented 3 years ago

When I put an image (jpg, png...) on a JLabel this is scaled to fit the screen DPI, but if interpolation is not enabled it looks really bad.

Example scaling 125% without interpolation: example_1

I have found a partial solution by overriding the JLabel paintComponent method:

@Override
public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    super.paintComponent(g2d);
}

Example scaling 125% with interpolation: example_2

Would it be possible to enable image interpolation by default in FlatLaf?

DevCharly commented 3 years ago

Looks much better 👍 Have you also tried RenderingHints.VALUE_INTERPOLATION_BICUBIC?

Would it be possible to enable image interpolation by default in FlatLaf?

Sounds like a good idea. Will try with some applications to find out whether this has drawbacks.

From another project, I can remember that scaling small icons (<= 16x16) to 200% results in blurred icons when using bicubic. In this case NEAREST_NEIGHBOR was better.

asomolinos commented 3 years ago

Hi @DevCharly,

Yes, I have tried bicubic and other RenderingHints but I have not seen much difference. Maybe, the best option is that it can be configured through UIManager:

UIManager.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

Thanks!

Chrriis commented 2 years ago

I am struggling with the same issue described this bug. In case it helps @asomolinos, I load my ImageIcons with the paintIcon method overridden, essentially to perform what NetBeans did: https://github.com/apache/netbeans/blob/4ae01ea70f4530443343beee3292e880a74099bd/platform/openide.util.ui/src/org/openide/util/ImageUtilities.java#L1193 (One change, round instead of cast to int at line 1209, or else icons might "jump").

From another project, I can remember that scaling small icons (<= 16x16) to 200% results in blurred icons when using bicubic. In this case NEAREST_NEIGHBOR was better.

When the scale factor is not an integral multiplication (e.g. 125%), NEAREST_NEIGHBOR is ugly. Blurry is an improvement.