Creating a Gray Version of an Icon - Java 2D Graphics

Java examples for 2D Graphics:Image

Description

Creating a Gray Version of an Icon

Demo Code

import java.awt.Image;

import javax.swing.GrayFilter;
import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Main {
  public Icon toGray(Icon icon) {
    if (icon instanceof ImageIcon) {
      Image grayImage = GrayFilter.createDisabledImage(((ImageIcon) icon).getImage());
      return new ImageIcon(grayImage);
    }/*  w ww.  j a v  a2s .  co m*/
    // Cannot convert
    return null;
  }
}

Related Tutorials