Beispiel #1
0
 private static BufferedImage makeBufferedImage(Icon icon, int w, int h) {
   BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D g = image.createGraphics();
   icon.paintIcon(null, g, (w - icon.getIconWidth()) / 2, (h - icon.getIconWidth()) / 2);
   g.dispose();
   return image;
 }
Beispiel #2
0
  static Icon reescala(Icon ic, int maxW, int maxH) {
    if (ic == null) {
      return null;
    }
    if (ic.getIconHeight() == maxH && ic.getIconWidth() == maxW) {
      return ic;
    }

    BufferedImage bi =
        new BufferedImage(ic.getIconHeight(), ic.getIconWidth(), BufferedImage.TYPE_INT_ARGB);

    Graphics g = bi.createGraphics();
    ic.paintIcon(null, g, 0, 0);
    g.dispose();

    Image bf = bi.getScaledInstance(maxW, maxH, Image.SCALE_SMOOTH);

    return new ImageIcon(bf);
  }