use of java.awt.image.ImageFilter in project jdk8u_jdk by JetBrains.
the class Image method getScaledInstance.
/**
* Creates a scaled version of this image.
* A new <code>Image</code> object is returned which will render
* the image at the specified <code>width</code> and
* <code>height</code> by default. The new <code>Image</code> object
* may be loaded asynchronously even if the original source image
* has already been loaded completely.
*
* <p>
*
* If either <code>width</code>
* or <code>height</code> is a negative number then a value is
* substituted to maintain the aspect ratio of the original image
* dimensions. If both <code>width</code> and <code>height</code>
* are negative, then the original image dimensions are used.
*
* @param width the width to which to scale the image.
* @param height the height to which to scale the image.
* @param hints flags to indicate the type of algorithm to use
* for image resampling.
* @return a scaled version of the image.
* @exception IllegalArgumentException if <code>width</code>
* or <code>height</code> is zero.
* @see java.awt.Image#SCALE_DEFAULT
* @see java.awt.Image#SCALE_FAST
* @see java.awt.Image#SCALE_SMOOTH
* @see java.awt.Image#SCALE_REPLICATE
* @see java.awt.Image#SCALE_AREA_AVERAGING
* @since JDK1.1
*/
public Image getScaledInstance(int width, int height, int hints) {
ImageFilter filter;
if ((hints & (SCALE_SMOOTH | SCALE_AREA_AVERAGING)) != 0) {
filter = new AreaAveragingScaleFilter(width, height);
} else {
filter = new ReplicateScaleFilter(width, height);
}
ImageProducer prod;
prod = new FilteredImageSource(getSource(), filter);
return Toolkit.getDefaultToolkit().createImage(prod);
}
use of java.awt.image.ImageFilter in project jdk8u_jdk by JetBrains.
the class FilteredImageSource method removeConsumer.
/**
* Removes an ImageConsumer from the list of consumers interested in
* data for this image.
*
* <p>
* This method is public as a side effect
* of this class implementing
* the <code>ImageProducer</code> interface.
* It should not be called from user code,
* and its behavior if called from user code is unspecified.
*
* @see ImageConsumer
*/
public synchronized void removeConsumer(ImageConsumer ic) {
if (proxies != null) {
ImageFilter imgf = (ImageFilter) proxies.get(ic);
if (imgf != null) {
src.removeConsumer(imgf);
proxies.remove(ic);
if (proxies.isEmpty()) {
proxies = null;
}
}
}
}
use of java.awt.image.ImageFilter in project jdk8u_jdk by JetBrains.
the class FilteredImageSource method startProduction.
/**
* Starts production of the filtered image.
* If the specified <code>ImageConsumer</code>
* isn't already a consumer of the filtered image,
* an instance of the original <code>ImageFilter</code>
* is created
* (using the filter's <code>getFilterInstance</code> method)
* to manipulate the image data
* for the <code>ImageConsumer</code>.
* The filter instance for the <code>ImageConsumer</code>
* is then passed to the <code>startProduction</code> method
* of the original <code>ImageProducer</code>.
*
* <p>
* This method is public as a side effect
* of this class implementing
* the <code>ImageProducer</code> interface.
* It should not be called from user code,
* and its behavior if called from user code is unspecified.
*
* @param ic the consumer for the filtered image
* @see ImageConsumer
*/
public void startProduction(ImageConsumer ic) {
if (proxies == null) {
proxies = new Hashtable();
}
ImageFilter imgf = (ImageFilter) proxies.get(ic);
if (imgf == null) {
imgf = filter.getFilterInstance(ic);
proxies.put(ic, imgf);
}
src.startProduction(imgf);
}
use of java.awt.image.ImageFilter in project jdk8u_jdk by JetBrains.
the class FilteredImageSource method addConsumer.
/**
* Adds the specified <code>ImageConsumer</code>
* to the list of consumers interested in data for the filtered image.
* An instance of the original <code>ImageFilter</code>
* is created
* (using the filter's <code>getFilterInstance</code> method)
* to manipulate the image data
* for the specified <code>ImageConsumer</code>.
* The newly created filter instance
* is then passed to the <code>addConsumer</code> method
* of the original <code>ImageProducer</code>.
*
* <p>
* This method is public as a side effect
* of this class implementing
* the <code>ImageProducer</code> interface.
* It should not be called from user code,
* and its behavior if called from user code is unspecified.
*
* @param ic the consumer for the filtered image
* @see ImageConsumer
*/
public synchronized void addConsumer(ImageConsumer ic) {
if (proxies == null) {
proxies = new Hashtable();
}
if (!proxies.containsKey(ic)) {
ImageFilter imgf = filter.getFilterInstance(ic);
proxies.put(ic, imgf);
src.addConsumer(imgf);
}
}
use of java.awt.image.ImageFilter in project litiengine by gurkenlabs.
the class ImageProcessing method applyAlphaChannel.
/**
* 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);
}
Aggregations