/** * Creates an image as negative of an existing one. It will basically replace the black color with white color. */ public static Image createNegativeImage(Image i) { return createImage(i, Color.black, Color.white); }
/** * Creates a version from an input image which replaces one color with another color. * * @param c The component to get properties useful for painting, e.g. the foreground or background color. * @param icon icon * @param oldColor the old color to be replaced. * @param newColor the new color that will replace the old color. * @return the image after replacing the color. */ public static ImageIcon createMaskImage(Component c, Icon icon, Color oldColor, Color newColor) { BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(c, image.getGraphics(), 0, 0); return new ImageIcon(MaskFilter.createImage(image, oldColor, newColor)); }