forked from yinchuandong/JavaVerify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScaleIcon.java
More file actions
42 lines (32 loc) · 1.05 KB
/
ScaleIcon.java
File metadata and controls
42 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package Widget;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import javax.swing.Icon;
public class ScaleIcon implements Icon {
private BufferedImage i = null;
private Icon icon = null;
public ScaleIcon(Icon icon) {
this.icon = icon;
}
@Override
public int getIconHeight() {
return icon.getIconHeight();
}
@Override
public int getIconWidth() {
return icon.getIconWidth();
}
public void paintIcon(Component c, Graphics g, int x, int y) {
float wid = c.getWidth();
float hei = c.getHeight();
int iconWid = icon.getIconWidth();
int iconHei = icon.getIconHeight();
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.scale(wid / iconWid, hei / iconHei);
icon.paintIcon(c, g2d, 0, 0);
}
}