Here you can find the source of changeBrightness(Icon icon, float factor)
Parameter | Description |
---|---|
icon | the ImageIcon to brighten |
factor | the factor to adjust brightness |
private static Icon changeBrightness(Icon icon, float factor)
//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; } }