Java Swing Icon changeBrightness(Icon icon, float factor)

Here you can find the source of changeBrightness(Icon icon, float factor)

Description

Brightens icons of type ImageIcon by a factor

License

Open Source License

Parameter

Parameter Description
icon the ImageIcon to brighten
factor the factor to adjust brightness

Return

the brightened icon, if icon is not instance of , the input icon is returned.

Declaration

private static Icon changeBrightness(Icon icon, float factor) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 BSI Business Systems Integration AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w ww.j  av  a2  s.c  o m*/
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Main {
    /**
     * Brightens icons of type {@link ImageIcon} by a factor
     * 
     * @param icon
     *          the ImageIcon to brighten
     * @param factor
     *          the factor to adjust brightness
     * @return the brightened icon, if icon is not instance of {@link ImageIcon}, the input icon is returned.
     */
    private static Icon changeBrightness(Icon icon, float factor) {
        if (icon == null || !(icon instanceof ImageIcon)) {
            return icon;
        }
        ImageIcon imageIcon = (ImageIcon) icon;

        ImageIcon ret = new ImageIcon();

        BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
                BufferedImage.TYPE_INT_ARGB);
        image.getGraphics().drawImage(imageIcon.getImage(), 0, 0, imageIcon.getImageObserver());

        RescaleOp op = new RescaleOp(factor, 0, null);
        image = op.filter(image, image);

        ret.setImage(image);
        return ret;
    }
}

Related

  1. areSizesEqual(javax.swing.Icon prevIcon, javax.swing.Icon nextIcon)
  2. blendIcon(Icon icon, float iconWeight, int rgb, float rgbWeight)
  3. blitBitmap(Graphics g, Icon icon, int x, int y, int w, int h)
  4. buildIcon(final String relativePath, final Class loader)
  5. clearMergedIconsCache()
  6. combineIcons(Icon underIcon, Icon overIcon)
  7. concatenateIcons(final Icon icon1, final Icon icon2)
  8. createBitmap(Icon icon)