Java Image Filter createIcon(ImageIcon icon, ImageFilter filter)

Here you can find the source of createIcon(ImageIcon icon, ImageFilter filter)

Description

Create a new icon which is filtered by some ImageFilter

License

Mozilla Public License

Declaration

private static synchronized ImageIcon createIcon(ImageIcon icon, ImageFilter filter) 

Method Source Code


//package com.java2s;
// The contents of this file are subject to the Mozilla Public License Version

import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;
import java.awt.image.ImageProducer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class Main {
    /** Create a new icon which is filtered by some ImageFilter */
    private static synchronized ImageIcon createIcon(ImageIcon icon, ImageFilter filter) {
        ImageProducer ip;//from ww w  .  j  a  v a2  s . c  o m
        Image image;
        MediaTracker tracker;

        ip = new FilteredImageSource(icon.getImage().getSource(), filter);
        image = Toolkit.getDefaultToolkit().createImage(ip);

        tracker = new MediaTracker(new JPanel());
        tracker.addImage(image, 1);

        try {
            tracker.waitForID(1);
        } catch (InterruptedException e) {
            e.printStackTrace();

            return null;
        }

        return new ImageIcon(image);
    }
}

Related

  1. createIcon(ImageIcon icon, ImageFilter filter)
  2. createKC854HiresImageFileFilter()
  3. createQualityResizedImage( Image orginalImage, int width, int height, boolean applySoftFilter, boolean keepRatio, Color bgColor, boolean fast)
  4. filter(ImageIcon image, RGBImageFilter filter)
  5. getImageIconFilter()