本文整理匯總了Java中java.awt.image.RGBImageFilter類的典型用法代碼示例。如果您正苦於以下問題:Java RGBImageFilter類的具體用法?Java RGBImageFilter怎麽用?Java RGBImageFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RGBImageFilter類屬於java.awt.image包,在下文中一共展示了RGBImageFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: applyAlphaChannel
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
/**
* 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);
}
示例2: makeColorTransparent
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
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);
}
示例3: makeColorTransparent
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
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)));
}
示例4: makeColorTransparent
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
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);
}
示例5: setTransparentColor
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
/**
*
* @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);
}
示例6: makeColorTransparent
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
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);
}
示例7: makeColorTransparent
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
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;
}
示例8: transformColorToTransparency
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
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);
}
示例9: makeColorTransparent
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
/**
* 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);
}
示例10: makeColorTransparent
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
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);
}
示例11: makeColorTransparent
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
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);
}
示例12: makeColorTransparent
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
/**
*
* 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);
}
示例13: toBufferedImageCanConvertFilteredImage
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
@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);
}
示例14: makeColorTransparent
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
/**
* 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);
}
示例15: makeTransparentWhite
import java.awt.image.RGBImageFilter; //導入依賴的package包/類
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);
}