Java Swing Icon darken(Icon icon)

Here you can find the source of darken(Icon icon)

Description

Returns a slightly darker version of the icon.

License

LGPL

Declaration

public static Icon darken(Icon icon) 

Method Source Code


//package com.java2s;
/*/*from w ww  .  ja  va 2  s. c o m*/
 * IconUtils.java
 *
 * Copyright (c) 2009 JAM Development Team
 *
 * This package is distributed under the Lesser Gnu Public Licence (LGPL)
 *
 */

import javax.swing.*;

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

public class Main {
    /**
     * Returns a slightly darker version of the icon.
     */
    public static Icon darken(Icon icon) {
        BufferedImage img = getBufferedImageFromIcon(icon);
        if (img == null)
            return icon;
        BufferedImageOp op = new RescaleOp(0.75f, 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

  1. createIconFromResource(ClassLoader loader, String resourceName)
  2. createIconFromStream(InputStream input)
  3. createTransparentIcon()
  4. createTransparentIcon(final int width, final int height)
  5. createTransparentIcon(int width)
  6. emptyIcon(final int width, final int height)
  7. getApplicationIcons()
  8. getBadgedIcon(Icon icon, Icon badge)
  9. getbtnIcon(String iconpath)