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);
}
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;
}
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;
}
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;
}
Aggregations