Search in sources :

Example 11 with ImageProducer

use of java.awt.image.ImageProducer 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)

Example 12 with ImageProducer

use of java.awt.image.ImageProducer in project TrakEM2 by trakem2.

the class ControlWindow method newJFrame.

private synchronized JFrame newJFrame(final String title) {
    final JFrame frame = new JFrame(title);
    if (null == icon) {
        try {
            Field mic = ImageJ.class.getDeclaredField("iconPath");
            mic.setAccessible(true);
            String path = (String) mic.get(IJ.getInstance());
            icon = IJ.getInstance().createImage((ImageProducer) new URL("file:" + path).getContent());
        } catch (Exception e) {
        }
    }
    if (null != icon)
        frame.setIconImage(icon);
    return frame;
}
Also used : Field(java.lang.reflect.Field) JFrame(javax.swing.JFrame) ImageProducer(java.awt.image.ImageProducer) URL(java.net.URL)

Example 13 with ImageProducer

use of java.awt.image.ImageProducer in project java-swing-tips by aterai.

the class SelectedImageFilter method makeRssButton.

private static JButton makeRssButton(ImageIcon rss) {
    JButton button = new JButton(rss);
    ImageProducer ip = new FilteredImageSource(rss.getImage().getSource(), new SelectedImageFilter());
    button.setRolloverIcon(new ImageIcon(button.getToolkit().createImage(ip)));
    // button.setRolloverIcon(makeFilteredImage(rss));
    // button.setRolloverIcon(makeFilteredImage2(rss));
    button.addActionListener(e -> System.out.println("clicked..."));
    button.setFocusPainted(false);
    button.setBorderPainted(false);
    button.setContentAreaFilled(false);
    button.setCursor(Cursor.getDefaultCursor());
    button.setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 2));
    return button;
}
Also used : ImageProducer(java.awt.image.ImageProducer) FilteredImageSource(java.awt.image.FilteredImageSource)

Example 14 with ImageProducer

use of java.awt.image.ImageProducer in project java-swing-tips by aterai.

the class RolloverFilter method makeImage.

private static BufferedImage makeImage(BufferedImage src, ImageFilter filter) {
    ImageProducer ip = src.getSource();
    Image img = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(ip, filter));
    int w = img.getWidth(null);
    int h = img.getHeight(null);
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics g = bi.createGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();
    return bi;
}
Also used : ImageProducer(java.awt.image.ImageProducer) FilteredImageSource(java.awt.image.FilteredImageSource) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage)

Aggregations

ImageProducer (java.awt.image.ImageProducer)14 FilteredImageSource (java.awt.image.FilteredImageSource)11 BufferedImage (java.awt.image.BufferedImage)5 ImageFilter (java.awt.image.ImageFilter)5 RGBImageFilter (java.awt.image.RGBImageFilter)4 Image (java.awt.Image)2 URL (java.net.URL)2 ImageIconUIResource (sun.swing.ImageIconUIResource)2 Dimension (java.awt.Dimension)1 GradientPaint (java.awt.GradientPaint)1 AreaAveragingScaleFilter (java.awt.image.AreaAveragingScaleFilter)1 ReplicateScaleFilter (java.awt.image.ReplicateScaleFilter)1 Field (java.lang.reflect.Field)1 Vector (java.util.Vector)1 ImageIcon (javax.swing.ImageIcon)1 JFrame (javax.swing.JFrame)1 Location (loci.common.Location)1 ReflectException (loci.common.ReflectException)1 CoreMetadata (loci.formats.CoreMetadata)1 FormatException (loci.formats.FormatException)1