From 0d3ce0f8a74688a845083ffa7969393dd2409a77 Mon Sep 17 00:00:00 2001 From: tc-wleite Date: Mon, 2 Oct 2023 18:01:38 -0300 Subject: [PATCH] '#1866: Better handling of RenderingHints. --- .../src/main/java/iped/utils/QualityIcon.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/iped-utils/src/main/java/iped/utils/QualityIcon.java b/iped-utils/src/main/java/iped/utils/QualityIcon.java index a3fc4cc38e..9a32f732f2 100644 --- a/iped-utils/src/main/java/iped/utils/QualityIcon.java +++ b/iped-utils/src/main/java/iped/utils/QualityIcon.java @@ -4,7 +4,10 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; +import java.awt.RenderingHints.Key; import java.awt.image.BufferedImage; +import java.util.HashMap; +import java.util.Map; import javax.swing.Icon; import javax.swing.ImageIcon; @@ -14,6 +17,16 @@ public class QualityIcon implements Icon { private final BufferedImage img; private int w, h; + private static final RenderingHints renderingHints; + + static { + Map hints = new HashMap(); + hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); + hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); + renderingHints = new RenderingHints(hints); + } + public QualityIcon(QualityIcon other, int size) { this.icon = other.icon; this.img = other.img; @@ -41,8 +54,8 @@ public QualityIcon(BufferedImage img, int size) { public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g; - g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); - g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + RenderingHints saveHints = g2.getRenderingHints(); + g2.setRenderingHints(renderingHints); if (img != null) { g2.drawImage(img, x, y, w, h, c); } else if (icon != null) { @@ -52,6 +65,7 @@ public void paintIcon(Component c, Graphics g, int x, int y) { icon.paintIcon(c, g, x, y); } } + g2.setRenderingHints(saveHints); } public int getIconWidth() {