Java 类java.awt.image.RGBImageFilter 实例源码

项目:litiengine    文件:ImageProcessing.java   
/**
 * All pixels that have the specified color are rendered transparent.
 *
 * @param img
 *          the img
 * @param color
 *          the color
 * @return the image
 */
public static Image applyAlphaChannel(final Image img, final Color color) {
  if (color == null || img == null) {
    return img;
  }

  final ImageFilter filter = new RGBImageFilter() {

    // the color we are looking for... Alpha bits are set to opaque
    public final int markerRGB = color.getRGB() | 0xFF000000;

    @Override
    public final int filterRGB(final int x, final int y, final int rgb) {
      if ((rgb | 0xFF000000) == this.markerRGB) {
        // Mark the alpha bits as zero - transparent
        return 0x00FFFFFF & rgb;
      } else {
        // nothing to do
        return rgb;
      }
    }
  };

  final ImageProducer ip = new FilteredImageSource(img.getSource(), filter);
  return Toolkit.getDefaultToolkit().createImage(ip);
}
项目:brModelo    文件:TratadorDeImagens.java   
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);
}
项目:OpenRS    文件:ImageUtils.java   
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)));
}
项目:SBOLDesigner    文件:Images.java   
public static Image makeColorTransparent(final BufferedImage im, final Color color) {
    final ImageFilter filter = new RGBImageFilter() {
        // the color we are looking for... 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);
    return Toolkit.getDefaultToolkit().createImage(ip);
}
项目:ComplexDataObject    文件:BufferedImageTools.java   
/**
 * 
 * @param im
 * @param color
 * @return
 */
public static Image setTransparentColor(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;

        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);
}
项目:torgo    文件:ImageUtils.java   
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
        @Override
        public int filterRGB(int x, int y, int rgb) {
            int markerRGB = color.getRGB() | 0xFF000000;

            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);
}
项目:OS-Cache-Suite    文件:ImageUtilities.java   
public static BufferedImage makeColorTransparent(BufferedImage im, final Color color) {
    RGBImageFilter 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;
            }
        }
    };
    ImageProducer ip = new FilteredImageSource(im.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;
}
项目:WorldGrower    文件:ImageInfoReader.java   
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);
}
项目:MeteoInfoLib    文件:GlobalUtil.java   
/**
 * 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);
}
项目:mobac    文件:OpenSeaMap.java   
public static Image makeColorTransparent(Image 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;

        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);
}
项目:SquaresInteractive    文件:Transparency.java   
public static Image makeColorTransparent(Image im, final Color color, final int alpha) {

        final ImageFilter filter = new RGBImageFilter() {

            // the color we are looking for... Alpha bits are set to opaque
            public int markerRGB = color.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 | (alpha << 24)) & rgb;
                }
                else {
                    // nothing to do
                    return rgb;
                }
            }
        }; 

        ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
        return Toolkit.getDefaultToolkit().createImage(ip);
    }
项目:momo3-backend    文件:GraphicsUtil.java   
/**
 *
 * Credits go to http://stackoverflow.com/a/665483 and
 * http://www.logikdev.com/2011/10/05/make-image-backgrounds-transparent-with-tolerance/
 *
 * @param im
 * @param colorToMakeTransparent
 * @param tolerance
 *
 * @return
 */
public static Image makeColorTransparent(final BufferedImage im, final Color colorToMakeTransparent, final int tolerance) {

    final ImageFilter transparencyfilter = new RGBImageFilter() {

        @Override
        public int filterRGB(int x, int y, int rgb) {
            final Color filterColor = new Color(rgb);

            if(colorsAreSimilar(filterColor, colorToMakeTransparent, tolerance)) {
                // Mark the alpha bits as zero - transparent
                return 0x00FFFFFF & rgb;
            } else {
                // Nothing to do
                return rgb;
            }

        }

    };

    final ImageProducer ip = new FilteredImageSource(im.getSource(), transparencyfilter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}
项目:vectorgraphics2d    文件:GraphicsUtilsTest.java   
@Test
public void toBufferedImageCanConvertFilteredImage() {
    Image image = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(
        new BufferedImage(
                TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB).getSource(),
        new RGBImageFilter() {
            @Override
            public int filterRGB(int x, int y, int rgb) {
                return rgb & 0xff;
            }
        }
    ));

    BufferedImage result = GraphicsUtils.toBufferedImage(image);

    assertBufferedImageEquals(image, result);
}
项目:shanks-wsn-module    文件:ImageLoaderHelper.java   
/**
 * 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 Image makeColorTransparent(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);
    return Toolkit.getDefaultToolkit().createImage(ip);
}
项目:FAO_Application    文件:BufferedImageRaster.java   
public static Image makeTransparentWhite(BufferedImage im, final Color color){
    ImageFilter filter = new RGBImageFilter() {

           // the color we are looking for... Alpha bits are set to opaque
           public int markerRGB = 0x00FFFFFF;

           public final int filterRGB(int x, int y, int rgb) {
               if ((rgb & 0x00FFFFFF) == markerRGB) {
                   // Mark the alpha bits as zero - transparent
                   return color.getRGB();// & 0xFFFFFFFF;
               } else {
                   // nothing to do
                   return rgb;
               }
           }
       };
       ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
       return Toolkit.getDefaultToolkit().createImage(ip);
}
项目:FAO_Application    文件:BufferedImageRaster.java   
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;

        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);
}
项目:hortonmachine    文件:ImageUtilities.java   
/**
 * 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;
}
项目:darkedenkit    文件:PkSpriteExtractor.java   
private BufferedImage filterWhiteToTransparent(Image img)
{       
    ImageFilter filter = new RGBImageFilter() {
        @Override
        public int filterRGB(int x, int y, int rgb)
        {
            return (rgb & 0x00FFFFFF) == 0x00FFFFFF ? 0x00FFFFFF : rgb;
        }
    };

    Image transparentImage = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(img.getSource(), filter));

    BufferedImage canvas = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = (Graphics2D)canvas.getGraphics();
    g.drawImage(transparentImage, 0, 0, null);
    g.dispose();

    return canvas;
}
项目:com.opendoorlogistics    文件:CachedGeomImageRenderer.java   
private BufferedImage createColouredImage(Image bwImage, final Color renderCol) {
    // create coloured image
    RGBImageFilter rgbFilter = new RGBImageFilter() {

        @Override
        public int filterRGB(int x, int y, int rgb) {
            Color current = new Color(rgb);
            int red = current.getRed();
            if (current.getAlpha() == 0 || red == 0) {
                return 0;
            }
            double factor = red / 255.0;
            int newRed = Colours.to0To255Int(renderCol.getRed() * factor);
            int newBlue = Colours.to0To255Int(renderCol.getBlue() * factor);
            int newGreen = Colours.to0To255Int(renderCol.getGreen() * factor);
            Color newCol = new Color(newRed, newGreen, newBlue, renderCol.getAlpha());
            return newCol.getRGB();
        }
    };

    // transform to colour and save in colour
    ImageProducer ip = new FilteredImageSource(bwImage.getSource(), rgbFilter);
    Image coloured = Toolkit.getDefaultToolkit().createImage(ip);
    BufferedImage colourImage = ImageUtils.toBufferedImage(coloured);
    return colourImage;
}
项目:XPressOnTechnologies    文件:ImageUtils.java   
public static Image makeColorTransparent(Image 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;

        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);
}
项目:incubator-netbeans    文件:MetalLFCustoms.java   
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;
}
项目:JDigitalSimulator    文件:Guitilities.java   
public static Image makeColorTransparent(Image image, final Color color) {
    ImageFilter filter = new RGBImageFilter() {
        public int markerRGB = color.getRGB()|0xFF000000;
        @Override
        public final int filterRGB(int x, int y, int rgb) {
            if((rgb|0xFF000000)==markerRGB)
                return 0x00FFFFFF & rgb;
            else return rgb;
        }
    };
    return Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(image.getSource(), filter));
}
项目:openjdk-jdk10    文件:HeadlessRGBImageFilter.java   
public static void main(String args[]) {
    new RGBImageFilter() {
        public int filterRGB(int x, int y, int rgb) {
            return 0;
        }
    }.clone();
}
项目:openjdk9    文件:HeadlessRGBImageFilter.java   
public static void main(String args[]) {
    new RGBImageFilter() {
        public int filterRGB(int x, int y, int rgb) {
            return 0;
        }
    }.clone();
}
项目:TuxGuitar-1.3.1-fork    文件:TGImageImpl.java   
public void applyTransparency( final TGColor background ){
    ImageFilter filter = new RGBImageFilter() {
        public int markerRGB = (((TGColorImpl)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));
}
项目:pathvisio    文件:ColorByExpression.java   
Image doReplaceColor(Image img, final Color oldColor, final Color newColor, final int tol) {
    RGBImageFilter f = new RGBImageFilter() {
        public int filterRGB(int x, int y, int rgb) {
            Color thisColor = new Color(rgb);
            if(compareColor(oldColor, thisColor, tol)) {
                return newColor.getRGB();
            }
            return rgb;
        }
    };
    ImageProducer pr = new FilteredImageSource(img.getSource(), f);
    return Toolkit.getDefaultToolkit().createImage(pr);
}
项目:intellij-ce-playground    文件:ColorBlindnessTest.java   
private static void compareFilters(ImageFilter one, ImageFilter two) {
  RGBImageFilter rgb1 = (RGBImageFilter)one;
  RGBImageFilter rgb2 = (RGBImageFilter)two;
  for (int i = 0; i < 0x01000000; i++) {
    assertEquals(rgb1.filterRGB(0, 0, i), rgb2.filterRGB(0, 0, i));
  }
}
项目:NBModeler    文件:SVGImageUtilities.java   
/**
 * Loads an icon based on resource path. Similar to
 * {@link #loadImage(String, boolean)}, returns ImageIcon instead of Image.
 *
 * @param resource resource path of the icon (no initial slash)
 * @param localized localized resource should be used
 * @return ImageIcon or null, if the icon cannot be loaded.
 * @since 7.22
 */
public static final ImageIcon loadImageIcon(String resource, boolean localized) {
    Image image = getIcon(resource, localized);
    if (image == null) {
        return null;
    }
    RGBImageFilter imageFilter = getImageIconFilter();
    if (null != imageFilter) {
        image = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(image.getSource(), imageFilter));
    }
    return (ImageIcon) image2Icon(image);
}
项目:AppWoksUtils    文件:IconIO.java   
public static BufferedImage colorRangeToTransparency(final BufferedImage image, final Color c1, final Color c2) {

        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();
        final ImageFilter filter = new RGBImageFilter() {
            @Override
            public final int filterRGB(final int x, final int y, final int rgb) {

                final int r = (rgb & 0xFF0000) >> 16;
                final int g = (rgb & 0xFF00) >> 8;
                final int b = rgb & 0xFF;
                if (r >= r1 && r <= r2 && g >= g1 && g <= g2 && b >= b1 && b <= b2) {
                    // Set fully transparent but keep color
                    // calculate a alpha value based on the distance between the
                    // range borders and the pixel color
                    final int dist = (Math.abs(r - (r1 + r2) / 2) + Math.abs(g - (g1 + g2) / 2) + Math.abs(b - (b1 + b2) / 2)) * 2;

                    return new Color(r, g, b, Math.min(255, dist)).getRGB();
                }

                return rgb;
            }
        };

        final ImageProducer ip = new FilteredImageSource(image.getSource(), filter);
        final Image img = Toolkit.getDefaultToolkit().createImage(ip);
        return IconIO.toBufferedImage(img);
    }
项目:Android-to-PC-Presentation    文件:UtilPC.java   
/** RGB icersinde belirlenmis bir rengi transparan yapar */
public static Image makeColorTransparent(BufferedImage im, final Color color) {
    ImageFilter filter = new RGBImageFilter() {
        /* ARGB formatinda A = 255 ve RGB olarak ekleniyor */
        public final int markerRGB = color.getRGB() | 0xFF000000;
        public final int filterRGB(int x, int y, int rgb) {
            if ((rgb | 0xFF000000) == markerRGB)
                return 0x00FFFFFF & rgb; // eger renk belirlenen renk ise transparan yapar
            else
                return rgb; // degilse aynen birakir
        }
    };
    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}
项目:java-image-processing-survival-guide    文件:InvertingImageComparator.java   
/**
 * 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;
}
项目:com.opendoorlogistics    文件:Functions.java   
@Override
protected ImageFilter createFilter(Object[] executed) {
    final Color filterCol = Colours.toColour(executed[1]);
    if (filterCol == null) {
        return null;
    }

    final Double lerpValue = Numbers.toDouble(executed[2]);
    if (lerpValue == null) {
        return null;
    }

    ImageFilter filter = new RGBImageFilter() {

        @Override
        public int filterRGB(int x, int y, int rgb) {
            // pass directly if completely transparent
            Color pixelCol = new Color(rgb, true);
            if (pixelCol.getAlpha() == 0) {
                return rgb;
            }

            // lerp between the two according to the lerp value
            Color lerped = Colours.lerp(pixelCol, filterCol, lerpValue);
            return lerped.getRGB();
        }
    };
    return filter;
}
项目:com.opendoorlogistics    文件:NOVLPolyLayerTile.java   
/**
 * @param colours
 * @return
 */
private RGBImageFilter createRGBFilter(final TIntObjectHashMap<Color> colours,final boolean isBorderRendering) {
    return new RGBImageFilter() {
        int lastInputRGB;
        int lastOutputRGB;

        @Override
        public int filterRGB(int x, int y, int rgb) {
            // remove alpha channel as can't get it to work right.... may give max 16 million objects
            rgb = rgb & 0x00FFFFFF;

            if(rgb!=0){

                // Do a speedup to stop to many hashtable queries. 
                // Often we will call this method for the same object twice in a row
                if(rgb == lastInputRGB){
                    return lastOutputRGB;
                }       

                // Get colour from input map using rgb as id
                Color col = colours.get(rgb);
                if(col!=null){

                    if(isBorderRendering){
                        col = DatastoreRenderer.getDefaultPolygonBorderColour(col);
                    }

                    lastInputRGB = rgb;
                    rgb = col.getRGB();
                    lastOutputRGB = rgb;
                }
                else{
                    // Hide it as not visible
                    rgb = 0;
                }
            }
            return rgb;
        }
    };
}
项目:ivp2java    文件:IconButtonUI.java   
/**
 * Change the brightness of an image
 */
private Image changeBrightness(Image img, final boolean brighten, final int percent) {
    ImageFilter filter = new RGBImageFilter() {
        public int filterRGB(int x, int y, int rgb) {
            return (rgb & 0xff000000) | (filter(rgb >> 16) << 16) | (filter(rgb >> 8) << 8) | (filter(rgb));
        }

        /**
         * Brighens or darkens a single r/g/b value.
         */
        private int filter(int color) {
            color = color & 0xff;
            if (brighten) {
                color = (255 - ((255 - color) * (100 - percent) / 100));
            } else {
                color = (color * (100 - percent) / 100);
            }
            if (color < 0)
                color = 0;
            if (color > 255)
                color = 255;
            return color;
        }
    };
    ImageProducer prod = new FilteredImageSource(img.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(prod);
}
项目:consulo    文件:BalloonImpl.java   
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
      }
      else {
        return rgb;
      }
    }
  };
  return ImageUtil.filter(image, filter);
}
项目:incubator-netbeans    文件:ImageUtilities.java   
/**
 * Loads an image based on resource path.
 * Exactly like {@link #loadImage(String)} but may do a localized search.
 * For example, requesting <samp>org/netbeans/modules/foo/resources/foo.gif</samp>
 * might actually find <samp>org/netbeans/modules/foo/resources/foo_ja.gif</samp>
 * or <samp>org/netbeans/modules/foo/resources/foo_mybranding.gif</samp>.
 * 
 * <p>Caching of loaded images can be used internally to improve performance.
 * <p> Since version 8.12 the returned image object responds to call
 * <code>image.getProperty("url", null)</code> by returning the internal
 * {@link URL} of the found and loaded <code>resource</code>.
 * 
 * <p>If the current look and feel is 'dark' (<code>UIManager.getBoolean("nb.dark.theme")</code>)
 * then the method first attempts to load image <i>&lt;original file name&gt;<b>_dark</b>.&lt;original extension&gt;</i>.
 * If such file doesn't exist the default one is loaded instead.
 * </p>
 * 
 * @param resource resource path of the image (no initial slash)
 * @param localized true for localized search
 * @return icon's Image or null if the icon cannot be loaded
 */
public static final Image loadImage(String resource, boolean localized) {
    Image 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 = Toolkit.getDefaultToolkit()
                    .createImage(new FilteredImageSource(image.getSource(), imageFilter));
        }
    }
    return image;
}
项目:SweetHome3D    文件:SwingTools.java   
/**
 * Returns the image matching a given pattern.
 */
public static BufferedImage getPatternImage(TextureImage pattern, Color backgroundColor, Color foregroundColor)
{
    if (patternImages == null)
    {
        patternImages = new HashMap<TextureImage, BufferedImage>();
    }
    BufferedImage image = new BufferedImage((int) pattern.getWidth(), (int) pattern.getHeight(),
            BufferedImage.TYPE_INT_RGB);
    Graphics2D imageGraphics = (Graphics2D) image.getGraphics();
    imageGraphics.setColor(backgroundColor);
    imageGraphics.fillRect(0, 0, image.getWidth(), image.getHeight());
    // Get pattern image from cache
    BufferedImage patternImage = patternImages.get(pattern);
    if (patternImage == null)
    {
        try
        {
            InputStream imageInput = pattern.getImage().openStream();
            patternImage = ImageIO.read(imageInput);
            imageInput.close();
            patternImages.put(pattern, patternImage);
        }
        catch (IOException ex)
        {
            throw new IllegalArgumentException("Can't read pattern image " + pattern.getName());
        }
    }
    // Draw the pattern image with foreground color
    final int foregroundColorRgb = foregroundColor.getRGB() & 0xFFFFFF;
    imageGraphics.drawImage(Toolkit.getDefaultToolkit()
            .createImage(new FilteredImageSource(patternImage.getSource(), new RGBImageFilter()
            {
                {
                    this.canFilterIndexColorModel = true;
                }

                @Override
                public int filterRGB(int x, int y, int argb)
                {
                    // Always use foreground color and alpha
                    return (argb & 0xFF000000) | foregroundColorRgb;
                }
            })), 0, 0, null);
    imageGraphics.dispose();
    return image;
}
项目:intellij-ce-playground    文件:ColorBlindnessTest.java   
private static void testZeroFilter(ImageFilter filter) {
  RGBImageFilter rgb = (RGBImageFilter)filter;
  for (int i = 0; i < 0x01000000; i++) {
    assertEquals(i, rgb.filterRGB(0, 0, i));
  }
}
项目:terminal-angel-disease    文件:TileSet.java   
private Surface trans(Surface origin, RGBImageFilter filter) {
    Image image = ImageTool.createFiltered(origin.image(), filter);
    return new Surface(image, true);
}
项目:com.opendoorlogistics    文件:NOVLPolyLayerTile.java   
private static BufferedImage applyColourFiltering(Image uncompressed, RGBImageFilter rgbFilter) {
    ImageProducer ip = new FilteredImageSource(uncompressed.getSource(), rgbFilter);
    Image coloured = Toolkit.getDefaultToolkit().createImage(ip);
    return ImageUtils.toBufferedImage(coloured);
}