Skip to content

Commit

Permalink
'#1866: Better handling of RenderingHints.
Browse files Browse the repository at this point in the history
  • Loading branch information
wladimirleite committed Oct 2, 2023
1 parent 143a3ac commit 0d3ce0f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions iped-utils/src/main/java/iped/utils/QualityIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +17,16 @@ public class QualityIcon implements Icon {
private final BufferedImage img;
private int w, h;

private static final RenderingHints renderingHints;

static {
Map<Key, Object> hints = new HashMap<Key, Object>();
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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down

0 comments on commit 0d3ce0f

Please sign in to comment.