下面列出了怎么用java.awt.image.FilteredImageSource的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
@Override
public Icon getDisabledIcon( JComponent component, Icon icon ) {
if( icon instanceof ImageIcon ) {
Object grayFilter = UIManager.get( "Component.grayFilter" );
ImageFilter filter = (grayFilter instanceof ImageFilter)
? (ImageFilter) grayFilter
: GrayFilter.createDisabledIconFilter( isDark() ); // fallback
Function<Image, Image> mapper = img -> {
ImageProducer producer = new FilteredImageSource( img.getSource(), filter );
return Toolkit.getDefaultToolkit().createImage( producer );
};
Image image = ((ImageIcon)icon).getImage();
return new ImageIconUIResource( MultiResolutionImageSupport.map( image, mapper ) );
}
return null;
}
/**
* 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);
}
/**
* 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);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
@Override
protected Image createAndPaintImage(
Component c, ColorModel colorModel, int deviceWidth, int deviceHeight, double scale)
{
final BufferedImage img = createBufferedImage(colorModel, deviceWidth, deviceHeight);
final Graphics2D imgG = img.createGraphics();
try {
imgG.clip(new Rectangle(0, 0, img.getWidth(), img.getHeight()));
imgG.scale(scale, scale);
delegate.paintIcon(c, imgG, 0, 0);
} finally {
imgG.dispose();
}
return Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(img.getSource(), filter));
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
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);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
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)));
}
/**
* 图像切割(指定切片的宽度和高度)
* @param bi 原图像
* @param x 裁剪原图像起点坐标X
* @param y 裁剪原图像起点坐标Y
* @param width 目标切片宽度
* @param height 目标切片高度
* @return
*/
public static BufferedImage cut(BufferedImage bi,int x, int y, int width, int height) {
BufferedImage tag = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = tag.createGraphics();
tag = g2.getDeviceConfiguration().createCompatibleImage(width, height,
Transparency.TRANSLUCENT);
g2.dispose();
g2 = tag.createGraphics();
int srcWidth = bi.getHeight(); // 源图宽度
int srcHeight = bi.getWidth(); // 源图高度
if (srcWidth > 0 && srcHeight > 0) {
ImageFilter cropFilter = new CropImageFilter(x, y, width, height);
Image img = Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(bi.getSource(),cropFilter));
g2.drawImage(img, 0, 0, width, height, null); // 绘制切割后的图
g2.dispose();
}
return tag;
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
/**
* 图像切割(按指定起点坐标和宽高切割)
* @param srcImg 源图像地址
* @param outImg 切片后的图像地址
* @param x 目标切片起点坐标X
* @param y 目标切片起点坐标Y
* @param width 目标切片宽度
* @param height 目标切片高度
* @param imageType 图片类型
*/
public static void cut(File srcImg, File outImg, int x, int y, int width, int height,String imageType) throws Exception{
//读取源图像
BufferedImage bi = ImageIO.read(srcImg);
int srcWidth = bi.getHeight();//源图宽度
int srcHeight = bi.getWidth();//源图高度
if (srcWidth > 0 && srcHeight > 0) {
Image image = bi.getScaledInstance(srcWidth, srcHeight,Image.SCALE_DEFAULT);
//四个参数分别为图像起点坐标和宽高
//即:CropImageFilter(int x,int y,int width,int height)
ImageFilter cropFilter = new CropImageFilter(x, y, width,height);
Image img = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(image.getSource(), cropFilter));
BufferedImage tag = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
Graphics g = tag.getGraphics();
g.drawImage(img, 0, 0, width, height, null);//绘制切割后的图
g.dispose();
//输出为文件
ImageIO.write(tag, imageType, outImg);
}
}
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);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
/**
* {@inheritDoc}
*
* @since 1.6
*/
public Icon getDisabledIcon(JComponent component, Icon icon) {
// if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
// client property set to Boolean.TRUE, then use the new
// hi res algorithm for creating the disabled icon (used
// in particular by the WindowsFileChooserUI class)
if (icon != null
&& component != null
&& Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
&& icon.getIconWidth() > 0
&& icon.getIconHeight() > 0) {
BufferedImage img = new BufferedImage(icon.getIconWidth(),
icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(component, img.getGraphics(), 0, 0);
ImageFilter filter = new RGBGrayFilter();
ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
Image resultImage = component.createImage(producer);
return new ImageIconUIResource(resultImage);
}
return super.getDisabledIcon(component, icon);
}
@Override public void paint(Graphics g, JComponent c) {
if (isPreventing && c instanceof JLayer) {
Dimension d = ((JLayer<?>) c).getView().getSize();
buf = Optional.ofNullable(buf)
.filter(bi -> bi.getWidth() == d.width && bi.getHeight() == d.height)
.orElseGet(() -> new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB));
Graphics2D g2 = buf.createGraphics();
super.paint(g2, c);
g2.dispose();
Image image = c.createImage(new FilteredImageSource(buf.getSource(), new RedGreenChannelSwapFilter()));
// BUG: cause an infinite repaint loop: g.drawImage(image, 0, 0, c);
g.drawImage(image, 0, 0, null);
} else {
super.paint(g, c);
}
}
/**
* 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;
}
private static Image postProcessImage(final Graphics2D g, final BufferedImage img, final Point textPos,
final Color bgColor, final Color fgColor) {
if (experimentalAntialiasingEnabled) {
final BufferedImage destImg = getImage(g);
ImageFilter filter = new AntialiasingImageFilter(destImg, textPos.x, textPos.y, fgColor, bgColor);
return Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(img.getSource(), filter));
} else {
return img;
}
}
protected Icon createDisabledIcon( Icon icon ) {
if( !(icon instanceof ImageIcon) )
return null;
Image image = ((ImageIcon) icon).getImage();
ImageProducer producer = new FilteredImageSource( image.getSource(), filter );
Image disabledImage = Toolkit.getDefaultToolkit().createImage( producer );
return new ImageIcon( disabledImage );
}
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;
}
public static void test(MyImageFilter testFilter) {
Image image = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
FilteredImageSource filtered =
new FilteredImageSource(image.getSource(), testFilter);
Image img = Toolkit.getDefaultToolkit().createImage(filtered);
BufferedImage buffImage = new BufferedImage(img.getWidth(null),
img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
}