java.awt.image.ImageFilter Java Examples

The following examples show how to use java.awt.image.ImageFilter. 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: ImageUtil.java    From imageServer with Apache License 2.0 6 votes vote down vote up
/**
 * 图像切割(指定切片的宽度和高度)
 * @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;
}
 
Example #2
Source File: WindowsLookAndFeel.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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);
}
 
Example #3
Source File: WindowsLookAndFeel.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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);
}
 
Example #4
Source File: ImageLoader.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Loads an image of available resolution (1x, 2x, ...) and scales to address the provided scale context.
 * Then wraps the image with {@link JBHiDPIScaledImage} if necessary.
 */
@Nullable
public static Image loadFromUrl(@Nonnull URL url, final boolean allowFloatScaling, boolean useCache, Supplier<ImageFilter>[] filters, final JBUI.ScaleContext ctx) {
  // We can't check all 3rd party plugins and convince the authors to add @2x icons.
  // In IDE-managed HiDPI mode with scale > 1.0 we scale images manually.

  return ImageDescList.create(url.toString(), null, UIUtil.isUnderDarcula(), allowFloatScaling, ctx).load(ImageConverterChain.create().
          withFilter(filters).
          with(new ImageConverter() {
            @Override
            public Image convert(Image source, ImageDesc desc) {
              if (source != null && desc.type != SVG) {
                double scale = adjustScaleFactor(allowFloatScaling, ctx.getScale(PIX_SCALE));
                if (desc.scale > 1) scale /= desc.scale; // compensate the image original scale
                source = scaleImage(source, scale);
              }
              return source;
            }
          }).
          withHiDPI(ctx), useCache);
}
 
Example #5
Source File: WindowsLookAndFeel.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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);
}
 
Example #6
Source File: WindowsLookAndFeel.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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);
}
 
Example #7
Source File: WindowsLookAndFeel.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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);
}
 
Example #8
Source File: WindowsLookAndFeel.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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);
}
 
Example #9
Source File: WindowsLookAndFeel.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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);
}
 
Example #10
Source File: WindowsLookAndFeel.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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);
}
 
Example #11
Source File: ImageUtils.java    From markdown-image-kit with MIT License 6 votes vote down vote up
/**
 * 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 #12
Source File: GlobalUtil.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #13
Source File: FlatLaf.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #14
Source File: WindowsLookAndFeel.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * {@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);
}
 
Example #15
Source File: CFSJCaptchaEngine.java    From Spring-MVC-Blueprints with MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
protected void buildInitialFactories() {
       int minWordLength = 7;
       int maxWordLength = 7;
       int fontSize = 36;
       int imageWidth = 300;
       int imageHeight = 90;
       WordGenerator wordGenerator = new RandomWordGenerator("0123456789ABCDEFGHIJKLTYREWSZabcdefghjkmnpqrstuvwxyz");
       TextPaster randomPaster = new DecoratedRandomTextPaster(
       		minWordLength,
               maxWordLength, 
               new RandomListColorGenerator(new Color[]{
               		new Color(23, 170, 27), new Color(220, 34, 11),
               		new Color(23, 67, 172)}), new TextDecorator[]{});
       BackgroundGenerator background = new UniColorBackgroundGenerator(imageWidth, imageHeight, Color.GREEN);
       FontGenerator font = new RandomFontGenerator(fontSize, fontSize,
               new Font[]{new Font("Calibri", Font.BOLD, fontSize),
                       new Font("Times New Roman", Font.PLAIN, fontSize),
                       new Font("Arial", Font.BOLD, fontSize)});
       ImageDeformation postDef = new ImageDeformationByFilters(new ImageFilter[]{});
       ImageDeformation backDef = new ImageDeformationByFilters(new ImageFilter[]{});
       ImageDeformation textDef = new ImageDeformationByFilters(new ImageFilter[]{});
       WordToImage word2image = new DeformedComposedWordToImage(font,
               background, randomPaster, backDef, textDef, postDef);
       addFactory(new GimpyFactory(wordGenerator, word2image));
   }
 
Example #16
Source File: ImageUtils.java    From OpenRS with GNU General Public License v3.0 6 votes vote down vote up
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 #17
Source File: CaptchaEngineEx.java    From DWSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void buildInitialFactories() {  
	        int minWordLength = 4;  
	        int maxWordLength = 5;  
	        /*int fontSize = 50;  
	        int imageWidth = 250;  
	        int imageHeight = 100;*/
	        int fontSize = 30;
	        int imageWidth = 120;  
	        int imageHeight = 50;
	        WordGenerator dictionnaryWords = new ComposeDictionaryWordGenerator(new FileDictionary("toddlist"));  
	        
	        // word2image components  
	        TextPaster randomPaster = new DecoratedRandomTextPaster(minWordLength,  
	                maxWordLength, new RandomListColorGenerator(new Color[] {  
	                        new Color(23, 170, 27), new Color(220, 34, 11),  
	                        new Color(23, 67, 172) }), new TextDecorator[] {});  
	       BackgroundGenerator background = new UniColorBackgroundGenerator(
	                imageWidth, imageHeight, Color.white);
//	        ColorGenerator colorGenerator=new RandomListColorGenerator(new Color[]{new Color(235, 234, 235),new Color(255, 255, 255)});
//	        BackgroundGenerator background=new FunkyBackgroundGenerator(imageWidth, imageHeight,colorGenerator);
	        FontGenerator font = new RandomFontGenerator(fontSize, fontSize,  
	                new Font[] { new Font("nyala", Font.BOLD, fontSize),  
	                        new Font("Bell MT", Font.PLAIN, fontSize),  
	                        new Font("Credit valley", Font.BOLD, fontSize) });  
	        ImageDeformation postDef = new ImageDeformationByFilters(  
	                new ImageFilter[] {});  
	        ImageDeformation backDef = new ImageDeformationByFilters(  
	                new ImageFilter[] {});  
	        ImageDeformation textDef = new ImageDeformationByFilters(  
	                new ImageFilter[] {});  
	  
	        WordToImage word2image = new DeformedComposedWordToImage(font,  
	                background, randomPaster, backDef, textDef, postDef);  
	        addFactory(new GimpyFactory(dictionnaryWords, word2image));  
	    }
 
Example #18
Source File: ImageUtil.java    From util with Apache License 2.0 5 votes vote down vote up
/**
 * 图像切割(按指定起点坐标和宽高切割)
 * @param srcImageFile 源图像地址
 * @param result 切片后的图像地址
 * @param x 目标切片起点坐标X
 * @param y 目标切片起点坐标Y
 * @param width 目标切片宽度
 * @param height 目标切片高度
 */
public final static void cut(String srcImageFile, String result,
        int x, int y, int width, int height) {
    try {
        // 读取源图像
        BufferedImage bi = ImageIO.read(new File(srcImageFile));
        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, "JPEG", new File(result));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #19
Source File: GMailEngine.java    From es with Apache License 2.0 5 votes vote down vote up
@Override
protected void buildInitialFactories() {

    // 图片和字体大小设置
    int minWordLength = 4;
    int maxWordLength = 5;
    int fontSize = 20;
    int imageWidth = 100;
    int imageHeight = 36;

    WordGenerator dictionnaryWords = new ComposeDictionaryWordGenerator(
            new FileDictionary("toddlist"));

    // word2image components
    TextPaster randomPaster = new DecoratedRandomTextPaster(minWordLength,
            maxWordLength, new RandomListColorGenerator(new Color[]{
            new Color(23, 170, 27), new Color(220, 34, 11),
            new Color(23, 67, 172)}), new TextDecorator[]{});
    BackgroundGenerator background = new UniColorBackgroundGenerator(
            imageWidth, imageHeight, Color.white);
    FontGenerator font = new RandomFontGenerator(fontSize, fontSize,
            new Font[]{new Font("nyala", Font.BOLD, fontSize),
                    new Font("Bell MT", Font.PLAIN, fontSize),
                    new Font("Credit valley", Font.BOLD, fontSize)});

    ImageDeformation postDef = new ImageDeformationByFilters(
            new ImageFilter[]{});
    ImageDeformation backDef = new ImageDeformationByFilters(
            new ImageFilter[]{});
    ImageDeformation textDef = new ImageDeformationByFilters(
            new ImageFilter[]{});

    WordToImage word2image = new DeformedComposedWordToImage(font,
            background, randomPaster, backDef, textDef, postDef);

    addFactory(new GimpyFactory(dictionnaryWords, word2image));
}
 
Example #20
Source File: ImageLoader.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Image loadFromUrl(@Nonnull URL url, boolean allowFloatScaling, final ImageFilter filter) {
  return loadFromUrl(url, allowFloatScaling, true, new Supplier[]{new Supplier() {
    @Override
    public Object get() {
      return filter;
    }
  }}, JBUI.ScaleContext.create());
}
 
Example #21
Source File: ImageLoader.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ImageConverterChain withFilter(final Supplier<ImageFilter> filter) {
  return with(new ImageConverter() {
    @Override
    public Image convert(Image source, ImageDesc desc) {
      return ImageUtil.filter(source, filter.get());
    }
  });
}
 
Example #22
Source File: AWTImage.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #23
Source File: IconLoader.java    From iconloader with Apache License 2.0 5 votes vote down vote up
public static void setFilter(ImageFilter filter) {
  if (!Registry.is("color.blindness.icon.filter")) {
    filter = null;
  }
  if (IMAGE_FILTER != filter) {
    IMAGE_FILTER = filter;
    clearCache();
  }
}
 
Example #24
Source File: ImageLoader.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Image loadFromStream(@Nonnull final InputStream inputStream, final int scale, final ImageFilter filter) {
  Image image = load(inputStream, scale);
  ImageDesc desc = new ImageDesc("", null, scale, IMG);
  return ImageConverterChain.create().withFilter(new Supplier<ImageFilter>() {
    @Override
    public ImageFilter get() {
      return filter;
    }
  }).withRetina().convert(image, desc);
}
 
Example #25
Source File: ImageLoader.java    From iconloader with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Image loadFromUrl(@NotNull URL url, boolean allowFloatScaling, ImageFilter filter) {
  final float scaleFactor = calcScaleFactor(allowFloatScaling);

  // We can't check all 3rd party plugins and convince the authors to add @2x icons.
  // (scaleFactor > 1.0) != isRetina() => we should scale images manually.
  // Note we never scale images on Retina displays because scaling is handled by the system.
  final boolean scaleImages = (scaleFactor > 1.0f) && !UIUtil.isRetina();

  // For any scale factor > 1.0, always prefer retina images, because downscaling
  // retina images provides a better result than upscaling non-retina images.
  final boolean loadRetinaImages = UIUtil.isRetina() || scaleImages;

  return ImageDescList.create(url.toString(), null, UIUtil.isUnderDarcula(), loadRetinaImages, allowFloatScaling).load(
    ImageConverterChain.create().
      withFilter(filter).
      withRetina().
      with(new ImageConverter() {
            public Image convert(Image source, ImageDesc desc) {
              if (source != null && scaleImages /*&& desc.type != ImageDesc.Type.SVG*/) {
                if (desc.path.contains("@2x"))
                  return scaleImage(source, scaleFactor / 2.0f);  // divide by 2.0 as Retina images are 2x the resolution.
                else
                  return scaleImage(source, scaleFactor);
              }
              return source;
            }
      }));
}
 
Example #26
Source File: StringPainter.java    From darklaf with MIT License 5 votes vote down vote up
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;
    }
}
 
Example #27
Source File: BalloonImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 #28
Source File: ImageInfoReader.java    From WorldGrower with GNU General Public License v3.0 4 votes vote down vote up
private BufferedImage createGhostImage(Image image) {
	ImageFilter filter = new GrayFilter(true, 50);  
	ImageProducer producer = new FilteredImageSource(image.getSource(), filter);  
	Image toolkitImage = Toolkit.getDefaultToolkit().createImage(producer);  
	return ImageUtils.toBufferedImage(toolkitImage);
}
 
Example #29
Source File: ImageHelper.java    From binnavi with Apache License 2.0 4 votes vote down vote up
public static Image filterImage(final Image inImage, final ImageFilter filter) {
  final ImageProducer imageProducer = new FilteredImageSource(inImage.getSource(), filter);
  return Toolkit.getDefaultToolkit().createImage(imageProducer);
}
 
Example #30
Source File: HeadlessImageFilter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) {
    new ImageFilter().clone();
}