Returns a slightly brighter version of the icon. - Java 2D Graphics

Java examples for 2D Graphics:Icon

Description

Returns a slightly brighter version of the icon.

Demo Code


//package com.java2s;
import javax.swing.*;

import java.awt.*;
import java.awt.image.*;

public class Main {
    /**/*  w w w. j  a v  a  2s. c  o m*/
     * Returns a slightly brighter version of the icon.
     */
    public static Icon brighten(Icon icon) {
        BufferedImage img = getBufferedImageFromIcon(icon);
        if (img == null)
            return icon;
        BufferedImageOp op = new RescaleOp(1.25f, 0, null);
        return new ImageIcon(op.filter(img, null));
    }

    /**
     * Creates a buffered image from an icon.
     */
    public static BufferedImage getBufferedImageFromIcon(Icon icon) {
        BufferedImage buffer = new BufferedImage(icon.getIconWidth(),
                icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics g = buffer.getGraphics();
        icon.paintIcon(new JLabel(), g, 0, 0);
        g.dispose();
        return buffer;
    }
}

Related Tutorials