java.awt.image.RGBImageFilter Java Examples
The following examples show how to use
java.awt.image.RGBImageFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Make a color of the image transparent. * * @param bufferedImageToProcess the image to extract the color from. * @param colorToMakeTransparent the color to make transparent. * @return the new image. */ public static BufferedImage makeColorTransparent( BufferedImage bufferedImageToProcess, final Color colorToMakeTransparent ) { ImageFilter filter = new RGBImageFilter(){ public int markerRGB = colorToMakeTransparent.getRGB() | 0xFF000000; public final int filterRGB( int x, int y, int rgb ) { if ((rgb | 0xFF000000) == markerRGB) { // Mark the alpha bits as zero - transparent return 0x00FFFFFF & rgb; } else { return rgb; } } }; ImageProducer ip = new FilteredImageSource(bufferedImageToProcess.getSource(), filter); Image image = Toolkit.getDefaultToolkit().createImage(ip); BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bufferedImage.createGraphics(); g2.drawImage(image, 0, 0, null); g2.dispose(); return bufferedImage; }
Example #2
Source File: ImageInfoReader.java From WorldGrower with GNU General Public License v3.0 | 6 votes |
private Image transformColorToTransparency(BufferedImage image, Color color) { ImageFilter filter = new RGBImageFilter() { public final int filterRGB(int x, int y, int rgb) { if (rgb == color.getRGB()) { return new Color(0, 0, 0, 0).getRGB(); } else { return rgb; } } }; ImageProducer ip = new FilteredImageSource(image.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(ip); }
Example #3
Source File: ImageUtils.java From OpenRS with GNU General Public License v3.0 | 6 votes |
public static BufferedImage makeColorTransparent(BufferedImage im, final Color color) { ImageFilter filter = new RGBImageFilter() { public int markerRGB = color.getRGB() | 0xFF000000; public final int filterRGB(int x, int y, int rgb) { if ((rgb | 0xFF000000) == markerRGB) { return 0x00FFFFFF & rgb; } else { return rgb; } } }; return imageToBufferedImage( Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(im.getSource(), filter))); }
Example #4
Source File: TratadorDeImagens.java From brModelo with GNU General Public License v3.0 | 6 votes |
public static Image makeColorTransparent(Image im, final Color color) { //(C) //Copiado da internet: 13/02/2011 - http://www.rgagnon.com/javadetails/java-0265.html e http://www.coderanch.com/t/331731/GUI/java/Resize-ImageIcon // ImageFilter filter = new RGBImageFilter() { // the color we are looking for... Alpha bits are set to opaque public int markerRGB = color.getRGB() | 0xFF000000; @Override public final int filterRGB(int x, int y, int rgb) { if ((rgb | 0xFF000000) == markerRGB) { // Mark the alpha bits as zero - transparent return 0x00FFFFFF & rgb; } else { // nothing to do return rgb; } } }; ImageProducer ip = new FilteredImageSource(im.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(ip); }
Example #5
Source File: GlobalUtil.java From MeteoInfo with GNU Lesser General Public License v3.0 | 6 votes |
/** * Make a color of a image transparent * * @param im The image * @param color The color * @return Result image */ public static Image makeColorTransparent(BufferedImage im, final Color color) { ImageFilter filter = new RGBImageFilter() { // the color we are looking for... Alpha bits are set to opaque public int markerRGB = color.getRGB() | 0xFF000000; @Override public final int filterRGB(int x, int y, int rgb) { if ((rgb | 0xFF000000) == markerRGB) { // Mark the alpha bits as zero - transparent return 0x00FFFFFF & rgb; } else { // nothing to do return rgb; } } }; ImageProducer ip = new FilteredImageSource(im.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(ip); }
Example #6
Source File: ImageUtils.java From markdown-image-kit with MIT License | 6 votes |
/** * http://stackoverflow.com/questions/665406/how-to-make-a-color-transparent-in-a-bufferedimage-and-save-as-png * * @param image the image * @return the image */ public static Image whiteToTransparent(@NotNull BufferedImage image) { ImageFilter filter = new RGBImageFilter() { int markerRGB = JBColor.WHITE.getRGB() | 0xFF000000; @Override public final int filterRGB(int x, int y, int rgb) { if ((rgb | 0xFF000000) == markerRGB) { // Mark the alpha bits as zero - transparent return 0x00FFFFFF & rgb; } else { // nothing to do return rgb; } } }; ImageProducer ip = new FilteredImageSource(image.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(ip); }
Example #7
Source File: ImageUtilities.java From netbeans with Apache License 2.0 | 6 votes |
private static ToolTipImage loadImageInternal(String resource, boolean localized) { // Avoid a NPE that could previously occur in the isDarkLaF case only. See NETBEANS-2401. if (resource == null) { return null; } ToolTipImage image = null; if( isDarkLaF() ) { image = getIcon(addDarkSuffix(resource), localized); // found an image with _dark-suffix, so there no need to apply an // image filter to make it look nice using dark themes } if (null == image) { image = getIcon(resource, localized); // only non _dark images need filtering RGBImageFilter imageFilter = getImageIconFilter(); if (null != image && null != imageFilter) { image = icon2ToolTipImage(FilteredIcon.create(imageFilter, image), image.url); } } return image; }
Example #8
Source File: AWTIconLoaderFacade.java From consulo with Apache License 2.0 | 5 votes |
/** * Creates new icon with the filter applied. */ @Nullable public static Icon filterIcon(@Nonnull Icon icon, RGBImageFilter filter, @Nullable Component ancestor) { if (icon instanceof DesktopLazyImageImpl) icon = ((DesktopLazyImageImpl)icon).getOrComputeIcon(); if (icon == null) return null; if (!isGoodSize(icon)) { LOG.error(icon); // # 22481 return EMPTY_ICON; } if (icon instanceof CachedImageIcon) { icon = ((CachedImageIcon)icon).asDisabledIcon(); } else { final float scale; if (icon instanceof JBUI.ScaleContextAware) { scale = (float)((JBUI.ScaleContextAware)icon).getScale(SYS_SCALE); } else { scale = UIUtil.isJreHiDPI() ? JBUI.sysScale(ancestor) : 1f; } @SuppressWarnings("UndesirableClassUsage") BufferedImage image = new BufferedImage((int)(scale * icon.getIconWidth()), (int)(scale * icon.getIconHeight()), BufferedImage.TYPE_INT_ARGB); final Graphics2D graphics = image.createGraphics(); graphics.setColor(UIUtil.TRANSPARENT_COLOR); graphics.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight()); graphics.scale(scale, scale); icon.paintIcon(LabelHolder.ourFakeComponent, graphics, 0, 0); graphics.dispose(); Image img = ImageUtil.filter(image, filter); if (UIUtil.isJreHiDPI()) img = RetinaImage.createFrom(img, scale, null); icon = new JBImageIcon(img); } return icon; }
Example #9
Source File: FlatSVGIcon.java From FlatLaf with Apache License 2.0 | 5 votes |
@Override public void paintIcon( Component c, Graphics g, int x, int y ) { update(); Rectangle clipBounds = g.getClipBounds(); if( clipBounds != null && !clipBounds.intersects( new Rectangle( x, y, getIconWidth(), getIconHeight() ) ) ) return; // get gray filter RGBImageFilter grayFilter = null; if( c != null && !c.isEnabled() ) { Object grayFilterObj = UIManager.get( "Component.grayFilter" ); grayFilter = (grayFilterObj instanceof RGBImageFilter) ? (RGBImageFilter) grayFilterObj : GrayFilter.createDisabledIconFilter( dark ); } Graphics2D g2 = new GraphicsFilter( (Graphics2D) g.create(), ColorFilter.getInstance(), grayFilter ); try { FlatUIUtils.setRenderingHints( g2 ); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR ); paintSvg( g2, x, y ); } finally { g2.dispose(); } }
Example #10
Source File: BalloonImpl.java From consulo with Apache License 2.0 | 5 votes |
private Image makeColorTransparent(Image image, Color color) { final int markerRGB = color.getRGB() | 0xFF000000; ImageFilter filter = new RGBImageFilter() { @Override public int filterRGB(int x, int y, int rgb) { if ((rgb | 0xFF000000) == markerRGB) { return 0x00FFFFFF & rgb; // set alpha to 0 } return rgb; } }; return ImageUtil.filter(image, filter); }
Example #11
Source File: InvertingImageComparator.java From java-image-processing-survival-guide with Apache License 2.0 | 5 votes |
/** * Make provided image transparent wherever color matches the provided color. * * @param im BufferedImage whose color will be made transparent. * @param color Color in provided image which will be made transparent. * @return Image with transparency applied. */ public static BufferedImage createTransparentImage(final BufferedImage im, final Color color) { final ImageFilter filter = new RGBImageFilter() { // the color we are looking for (white)... Alpha bits are set to opaque public int markerRGB = color.getRGB() | 0xFFFFFFFF; public final int filterRGB(final int x, final int y, final int rgb) { if ((rgb | 0xFF000000) == markerRGB) { // Mark the alpha bits as zero - transparent return 0x00FFFFFF & rgb; } else { // nothing to do return rgb; } } }; final ImageProducer ip = new FilteredImageSource(im.getSource(), filter); final Image image = Toolkit.getDefaultToolkit().createImage(ip); final BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = bufferedImage.createGraphics(); g2.drawImage(image, 0, 0, null); g2.dispose(); return bufferedImage; }
Example #12
Source File: AWTImage.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public void applyTransparency( final UIColor background ){ ImageFilter filter = new RGBImageFilter() { public int markerRGB = (((AWTColor)background).getHandle().getRGB() | 0xFF000000); public final int filterRGB(int x, int y, int rgb) { if ( ( rgb | 0xFF000000 ) == markerRGB ) { return 0x00FFFFFF & rgb; } return rgb; } }; this.handle = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(this.handle.getSource(), filter)); }
Example #13
Source File: HeadlessRGBImageFilter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String args[]) { new RGBImageFilter() { public int filterRGB(int x, int y, int rgb) { return 0; } }.clone(); }
Example #14
Source File: MetalLFCustoms.java From netbeans with Apache License 2.0 | 5 votes |
private static Image filterImage( Image image ) { if( null == image ) return image; Object obj = UIManager.get("nb.imageicon.filter"); if( obj instanceof RGBImageFilter && null != image ) { RGBImageFilter imageIconFilter = ( RGBImageFilter ) obj; image = Toolkit.getDefaultToolkit().createImage( new FilteredImageSource( image.getSource(), imageIconFilter ) ); } return image; }
Example #15
Source File: FilteredIcon.java From netbeans with Apache License 2.0 | 5 votes |
public static Icon create(RGBImageFilter filter, Icon delegate) { final int width = delegate.getIconWidth(); final int height = delegate.getIconHeight(); if (width < 0 || height < 0) { /* This case was once observed in NETBEANS-3671. I'm not sure where the offending Icon came from. Log some more information for future debugging, and fall back gracefully. */ Object url = ImageUtilities.icon2Image(delegate).getProperty("url", null); LOG.log(Level.WARNING, "NETBEANS-3671: FilteredIcon.create got {0} of invalid dimensions {1}x{2} with URL={3}", new Object[] { delegate.getClass().getName(), width, height, url }); return delegate; } return new FilteredIcon(filter, delegate); }
Example #16
Source File: FilteredIcon.java From netbeans with Apache License 2.0 | 5 votes |
private FilteredIcon(RGBImageFilter filter, Icon delegate) { super(delegate.getIconWidth(), delegate.getIconHeight()); Parameters.notNull("filter", filter); Parameters.notNull("delegate", delegate); this.filter = filter; this.delegate = delegate; }
Example #17
Source File: FlatDisabledIconsTest.java From FlatLaf with Apache License 2.0 | 5 votes |
private void changed() { int brightness = intellijBrightnessSlider.getValue(); int contrast = intellijContrastSlider.getValue(); intellijBrightnessValue.setText( String.valueOf( brightness ) ); intellijContrastValue.setText( String.valueOf( contrast ) ); RGBImageFilter filter = new IntelliJGrayFilter( brightness, contrast, 100 ); firePropertyChange( "filter", null, filter ); }
Example #18
Source File: FlatDisabledIconsTest.java From FlatLaf with Apache License 2.0 | 5 votes |
private void metalLafChanged() { int min = metalLafMinSlider.getValue(); int max = metalLafMaxSlider.getValue(); metalLafMinValue.setText( String.valueOf( min ) ); metalLafMaxValue.setText( String.valueOf( max ) ); RGBImageFilter filter = new MetalDisabledButtonImageFilter( min, max ); updateFilter( metalLafToolBar, 3, filter ); }
Example #19
Source File: FlatDisabledIconsTest.java From FlatLaf with Apache License 2.0 | 5 votes |
private void basicLafChanged() { boolean brighter = basicLafBrighterCheckBox.isSelected(); int percent = basicLafPercentSlider.getValue(); basicLafPercentValue.setText( String.valueOf( percent ) ); RGBImageFilter filter = new GrayFilter( brighter, percent ); updateFilter( basicLafToolBar, 2, filter ); }
Example #20
Source File: FlatDisabledIconsTest.java From FlatLaf with Apache License 2.0 | 4 votes |
void setFilter( RGBImageFilter filter ) { this.filter = filter; updateDisabledIcon(); }
Example #21
Source File: FlatDisabledIconsTest.java From FlatLaf with Apache License 2.0 | 4 votes |
FilterButton( RGBImageFilter filter, Icon icon ) { this.filter = filter; setEnabled( false ); setIcon( icon ); }
Example #22
Source File: FlatDisabledIconsTest.java From FlatLaf with Apache License 2.0 | 4 votes |
private void updateFilter( JToolBar toolBar, int zipIndex, RGBImageFilter filter ) { for( Component c : toolBar.getComponents() ) ((FilterButton)c).setFilter( filter ); ((FilterButton)zipToolBar.getComponent( zipIndex )).setFilter( filter ); }
Example #23
Source File: FlatDisabledIconsTest.java From FlatLaf with Apache License 2.0 | 4 votes |
private void intelliJDarkFilterChanged(PropertyChangeEvent e) { updateFilter( intellijDarkToolBar, 7, (RGBImageFilter) e.getNewValue() ); }
Example #24
Source File: FlatDisabledIconsTest.java From FlatLaf with Apache License 2.0 | 4 votes |
private void intelliJLightFilterChanged(PropertyChangeEvent e) { updateFilter( intellijLightToolBar, 6, (RGBImageFilter) e.getNewValue() ); }
Example #25
Source File: FlatDisabledIconsTest.java From FlatLaf with Apache License 2.0 | 4 votes |
private void intelliJTextFilterChanged(PropertyChangeEvent e) { updateFilter( intellijTextToolBar, 5, (RGBImageFilter) e.getNewValue() ); }
Example #26
Source File: FlatSVGIcon.java From FlatLaf with Apache License 2.0 | 4 votes |
public GraphicsFilter( Graphics2D delegate, ColorFilter colorFilter, RGBImageFilter grayFilter ) { super( delegate ); this.colorFilter = colorFilter; this.grayFilter = grayFilter; }