Java Swing Icon reescala(Icon ic, int maxW, int maxH)

Here you can find the source of reescala(Icon ic, int maxW, int maxH)

Description

reescala

License

Open Source License

Declaration

static Icon reescala(Icon ic, int maxW, int maxH) 

Method Source Code

//package com.java2s;
/*/*from w w w.  j  a  v  a  2s  . c o m*/
 *                 (C) Copyright 2005 Nilo J. Gonzalez
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser Gereral Public Licence as published by the Free
 * Software Foundation; either version 2 of the Licence, or (at your opinion) any
 * later version.
 * 
 * This library is distributed in the hope that it will be usefull, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of merchantability or fitness for a
 * particular purpose. See the GNU Lesser General Public Licence for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public Licence along
 * with this library; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, Ma 02111-1307 USA.
 *
 * http://www.gnu.org/licenses/lgpl.html (English)
 * http://gugs.sindominio.net/gnu-gpl/lgpl-es.html (Espa?ol)
 *
 *
 * Original author: Nilo J. Gonzalez
 */

import java.awt.*;

import java.awt.image.*;

import javax.swing.*;

public class Main {
    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);
    }
}

Related

  1. loadIcons(String list, String path, Set ignore, ClassLoader loader)
  2. loadLoadingIcon()
  3. makeButtcon(Icon icon, Icon rollover, String tooltip, boolean is_toggle)
  4. mergeComponentAndIcon(JComponent component, Icon icon)
  5. mergeIcons(Icon i1, Icon i2, int offsetRechtsOben)
  6. resize(Icon icon, int width, int height)
  7. scaleDown(Icon icon, int maxWidth, int maxHeight)
  8. setComponentTabIcon(Component component, Icon icon)
  9. sizeToIcon(JComponent component, Icon icon)