Search in sources :

Example 6 with ImageFilter

use of java.awt.image.ImageFilter in project ultimate-java by pantinor.

the class ImageTransparency method makeColorTransparent.

public static BufferedImage makeColorTransparent(BufferedImage im, final Color color) {
    final ImageFilter filter = new RGBImageFilter() {

        public int markerRGB = color.getRGB();

        public final int filterRGB(int x, int y, int rgb) {
            int alpha = (rgb >> 24) & 0xff;
            int red = (rgb >> 16) & 0xFF;
            int green = (rgb >> 8) & 0xFF;
            int blue = rgb & 0xFF;
            if (red == MARKER_RED && green == MARKER_GREEN && blue == MARKER_BLUE) {
                // Mark the alpha bits as zero - transparent
                rgb = 0x00FFFFFF & rgb;
            }
            alpha = (rgb >> 24) & 0xff;
            red = (rgb >> 16) & 0xFF;
            green = (rgb >> 8) & 0xFF;
            blue = rgb & 0xFF;
            return rgb;
        }
    };
    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    Image i = Toolkit.getDefaultToolkit().createImage(ip);
    sun.awt.image.ToolkitImage source = (sun.awt.image.ToolkitImage) i;
    source.preload(null);
    try {
        Thread.sleep(250);
    } catch (Exception e) {
    }
    return source.getBufferedImage();
}
Also used : RGBImageFilter(java.awt.image.RGBImageFilter) RGBImageFilter(java.awt.image.RGBImageFilter) ImageFilter(java.awt.image.ImageFilter) ImageProducer(java.awt.image.ImageProducer) FilteredImageSource(java.awt.image.FilteredImageSource) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage)

Example 7 with ImageFilter

use of java.awt.image.ImageFilter in project jdk8u_jdk by JetBrains.

the class WindowsLookAndFeel method getDisabledIcon.

/**
     * {@inheritDoc}
     *
     * @since 1.6
     */
public Icon getDisabledIcon(JComponent component, Icon icon) {
    // in particular by the WindowsFileChooserUI class)
    if (icon != null && component != null && Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY)) && icon.getIconWidth() > 0 && icon.getIconHeight() > 0) {
        BufferedImage img = new BufferedImage(icon.getIconWidth(), icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
        ImageFilter filter = new RGBGrayFilter();
        ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
        Image resultImage = component.createImage(producer);
        return new ImageIconUIResource(resultImage);
    }
    return super.getDisabledIcon(component, icon);
}
Also used : RGBImageFilter(java.awt.image.RGBImageFilter) ImageFilter(java.awt.image.ImageFilter) ImageIconUIResource(sun.swing.ImageIconUIResource) ImageProducer(java.awt.image.ImageProducer) FilteredImageSource(java.awt.image.FilteredImageSource) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage)

Example 8 with ImageFilter

use of java.awt.image.ImageFilter in project hutool by looly.

the class ImageUtil method cut.

/**
 * 图像切割(按指定起点坐标和宽高切割)
 *
 * @param srcImage 源图像
 * @param rectangle 矩形对象,表示矩形区域的x,y,width,height
 * @return {@link BufferedImage}
 * @since 3.1.0
 */
public static BufferedImage cut(Image srcImage, Rectangle rectangle) {
    final ImageFilter cropFilter = new CropImageFilter(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
    Image img = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(srcImage.getSource(), cropFilter));
    return toBufferedImage(img);
}
Also used : CropImageFilter(java.awt.image.CropImageFilter) ImageFilter(java.awt.image.ImageFilter) FilteredImageSource(java.awt.image.FilteredImageSource) CropImageFilter(java.awt.image.CropImageFilter) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage)

Example 9 with ImageFilter

use of java.awt.image.ImageFilter in project cytoscape-impl by cytoscape.

the class RingLayer method transformColorToTransparency.

// if pixel color is between c1 and c2 (inclusive), make it transparent
private static Image transformColorToTransparency(BufferedImage image, Color c1, Color c2) {
    // Primitive test, just an example
    final int r1 = c1.getRed();
    final int g1 = c1.getGreen();
    final int b1 = c1.getBlue();
    final int r2 = c2.getRed();
    final int g2 = c2.getGreen();
    final int b2 = c2.getBlue();
    ImageFilter filter = new RGBImageFilter() {

        @Override
        public final int filterRGB(int x, int y, int rgb) {
            int r = (rgb & 0x00ff0000) >> 16;
            int g = (rgb & 0x0000ff00) >> 8;
            int b = rgb & 0x000000ff;
            if (r >= r1 && r <= r2 && g >= g1 && g <= g2 && b >= b1 && b <= b2) {
                // alpha of 0 = transparent
                return rgb & 0x00FFFFFF;
            }
            return rgb;
        }
    };
    ImageProducer ip = new FilteredImageSource(image.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}
Also used : RGBImageFilter(java.awt.image.RGBImageFilter) RGBImageFilter(java.awt.image.RGBImageFilter) ImageFilter(java.awt.image.ImageFilter) ImageProducer(java.awt.image.ImageProducer) FilteredImageSource(java.awt.image.FilteredImageSource)

Aggregations

ImageFilter (java.awt.image.ImageFilter)9 FilteredImageSource (java.awt.image.FilteredImageSource)6 ImageProducer (java.awt.image.ImageProducer)5 RGBImageFilter (java.awt.image.RGBImageFilter)4 BufferedImage (java.awt.image.BufferedImage)3 Image (java.awt.Image)2 Hashtable (java.util.Hashtable)2 AreaAveragingScaleFilter (java.awt.image.AreaAveragingScaleFilter)1 CropImageFilter (java.awt.image.CropImageFilter)1 ReplicateScaleFilter (java.awt.image.ReplicateScaleFilter)1 ImageIconUIResource (sun.swing.ImageIconUIResource)1