Java Utililty Methods ImageIcon

List of utility methods to do ImageIcon

Description

The list of methods to do ImageIcon are organized into topic(s).

Method

ImageIcongetThumbnail(ImageIcon src, int maxWidth)
get Thumbnail
if (src != null) {
    if (src.getIconWidth() > maxWidth) {
        return new ImageIcon(src.getImage().getScaledInstance(maxWidth, -1, Image.SCALE_SMOOTH));
    } else { 
        return src;
return null;
...
int[]grabRGB(ImageIcon icon)
Grabs a RGB values of the given image icon
int width = icon.getIconWidth();
int height = icon.getIconHeight();
int[] rgb = new int[width * height];
PixelGrabber pg = new PixelGrabber(icon.getImage(), 0, 0, width, height, rgb, 0, width);
try {
    pg.grabPixels();
} catch (InterruptedException e) {
    throw new RuntimeException("Interrupted waiting for pixels!");
...
ImageIconiconDefaultSize(ImageIcon imag)
icon Default Size
ImageIcon imagen = new ImageIcon(imag.getImage().getScaledInstance(14, 14, java.awt.Image.SCALE_DEFAULT));
return imagen;
ImageIconimageFlip(int w, int h, ImageIcon... icons)
image Flip
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D ig2 = bi.createGraphics();
for (ImageIcon icon : icons) {
    ig2.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), null);
return new ImageIcon(bi);
byte[]imageToBytes(ImageIcon icon)
image To Bytes
if (icon == null) {
    return null;
Image img = icon.getImage();
if (img.getWidth(null) < 1 && img.getHeight(null) < 1) {
    return null;
BufferedImage image = getBufferedImageFromImage(img);
...
ImageIconimageWithBackground(ImageIcon icon, Color colorBg)
image With Background
if (icon != null) {
    BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D ig2 = bi.createGraphics();
    if (colorBg != null) {
        ig2.setColor(colorBg);
        ig2.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
    ig2.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), null);
    return new ImageIcon(bi);
return icon;
voidinitImageIcon(Class cl)
init Image Icon
imageApp = getImage(cl, "app.gif");
imageEvaluate = getImage(cl, "evaluateIcon.gif");
imageAbout = getImage(cl, "about.gif");
imageIconExpand = new ImageIcon(getImage(cl, "handleExpand.gif"));
imageIconCollapse = new ImageIcon(getImage(cl, "handleCollapse.gif"));
plusIcon = new ImageIcon(getImage(cl, "plus.gif"));
minusIcon = new ImageIcon(getImage(cl, "minus.gif"));
wizardIcon = new ImageIcon(getImage(cl, "wizard.gif"));
...
booleanisValidImg(ImageIcon img)
Verifica que la imagen tenga las dimensiones de 32x32
return (img.getIconWidth() == 32 && img.getIconHeight() == 32);
ImageIconloadJavaInternal(ImageIcon r, Dimension d, boolean noStretch)
load Java Internal
Image scaled = null;
Dimension newD = getSizeKeepRatio(new Dimension(r.getIconWidth(), r.getIconHeight()), d, noStretch);
if (newD == null) {
    return r;
scaled = r.getImage().getScaledInstance(newD.width, newD.height, Image.SCALE_FAST);
r.getImage().flush();
r.setImage(scaled);
...
ImageIconmakeDisabledImage(ImageIcon in)
make Disabled Image
if (in == null)
    return (null);
Image greyImage = makeGrayImage(in.getImage());
return (new ImageIcon(greyImage));