public static MaskFilter getInstance(Color oldColor, Color newColor) { if (_maskFilter == null) { _maskFilter = new MaskFilter(oldColor, newColor); } else { _maskFilter.setOldColor(oldColor); _maskFilter.setNewColor(newColor); } return _maskFilter; }
/** * 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 gray version from an input image. Usually gray icon indicates disabled. If input image is null, a blank * ImageIcon will be returned. * * @param image image * @return gray version of the image */ public static ImageIcon createNegativeImage(Image image) { if (image == null) return EMPTY_ICON; return new ImageIcon(MaskFilter.createNegativeImage(image)); }
/** * Creates an image from an existing one by replacing the old color with the new color. */ public static Image createImage(Image i, Color oldColor, Color newColor) { MaskFilter filter = MaskFilter.getInstance(oldColor, newColor); ImageProducer prod = new FilteredImageSource(i.getSource(), filter); Image image = Toolkit.getDefaultToolkit().createImage(prod); return image; }
/** * 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)); }
/** * Creates a negative version from an input black image which basically replaces black pixel with white pixel. * * @param c The component to get properties useful for painting, e.g. the foreground or background color. * @param icon icon * @return the negative version of the image */ public static ImageIcon createNegativeImage(Component c, Icon icon) { BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(c, image.getGraphics(), 0, 0); return new ImageIcon(MaskFilter.createNegativeImage(image)); }