/** * Creates a tinted image from an input image with a given color. If input image is null, a blank ImageIcon will be * returned. * * @param icon image * @param color the color * @return a tinted version of the image */ public static ImageIcon createTintedImage(ImageIcon icon, Color color) { if (icon == null) return EMPTY_ICON; return new ImageIcon(TintFilter.createTintedImage(icon.getImage(), color, null)); }
/** * Creates a tinted image * * @param i the original image * @param color the color to be tinted * @param insets the insets. The border area with the insets will not be tinted. * @return a tinted image */ public static Image createTintedImage(Image i, Color color, Insets insets) { TintFilter filter = new TintFilter(color, i.getWidth(null), i.getHeight(null), insets); ImageProducer prod = new FilteredImageSource(i.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(prod); } }