[Chapter 22] ImageFilter
Author: John Zukowski
Date: Thu Jul 31 15:25:17 1997

#

| Chapter 22 java.awt.image Reference |

# ImageFilter

## Name

ImageFilter

##

## Description

The `ImageFilter` class sits between the `ImageProducer` and `ImageConsumer` as an image is being created to provide a filtered version of that image. Image filters are always used in conjunction with a `FilteredImageSource`. As an implementer of the `ImageConsumer` interface, an image filter receives pixel data from the original image's source and delivers it to another image consumer. The `ImageFilter` class implements a null filter (i.e., the new image is the same as the original); to produce a filter that modifies an image, create a subclass of `ImageFilter`.

## Class Definition

    public class java.awt.image.ImageFilter
        extends java.lang.Object
        implements java.awt.image.ImageConsumer, java.lang.Cloneable {
      // Variables
      protected ImageConsumer consumer;
      // Constructors
      public ImageFilter();
      // Instance Methods
      public Object clone();
      public ImageFilter getFilterInstance (ImageConsumer ic);
      public void imageComplete (int status);
      public void resendTopDownLeftRight (ImageProducer ip);
      public void setColorModel (ColorModel model);
      public void setDimensions (int width, int height);
      public void setHints (int hints);
      public void setPixels (int x, int y, int width, int height,
          ColorModel model, byte[] pixels, int offset, int scansize);
      public void setPixels (int x, int y, int width, int height,
          ColorModel model, int[] pixels, int offset, int scansize);
      public void setProperties (Hashtable properties);
    }

## Protected Variables

### consumer

#### protected ImageConsumer consumer

The consumer variable is a reference to the actual `ImageConsumer` for the `Image`.

## Constructors

### ImageFilter

#### public ImageFilter()

Description

  Constructs an empty `ImageFilter` instance.

## Instance Methods

### clone

#### public Object clone()

Overrides

  `Object``.clone()`

Returns

  A copy of the `ImageFilter` instance.

### getFilterInstance

#### public ImageFilter getFilterInstance (ImageConsumer ic)

Parameters

  ic

    The consumer in question.

Returns

  A copy of the `ImageFilter` instance.

Description

  Returns the filter that will do the filtering for `ic`.

### imageComplete

#### void imageComplete (int status)

Parameters

  status

    Image loading completion status flags.

Implements

  `ImageConsumer.imageComplete(``int``)`

Description

  Called by the `ImageProducer` to indicate an image's completion status. `ImageFilter` passes these flags to the consumer unchanged.

### resendTopDownLeftRight

#### public void resendTopDownLeftRight (ImageProducer ip)

Parameters

  ip

    The `ImageProducer` generating the original image.

Description

  Called by the `ImageConsumer` to ask the filter to resend the image data in the top-down, left-to-right order. In `ImageFilter`, this method calls the same method in the `ImageProducer`, thus relaying the request.

### setColorModel

#### void setColorModel (ColorModel model)

Parameters

  model

    The color model for the image.

Implements

  `ImageConsumer.setColorModel(``ColorModel``)`

Description

  Sets the image's color model.

### setDimensions

#### void setDimensions (int width, int height)

Parameters

  width

    Width for image.

  height

    Height for image.

Implements

  `ImageConsumer.setDimensions(``int, int``)`

Description

  Sets the image's dimensions.

### setHints

#### void setHints (int hints)

Parameters

  hints

    Image consumption hints.

Implements

  `ImageConsumer.setHints(``int``)`

Description

  Called by the `ImageProducer` to deliver hints about how the image data will be delivered. `ImageFilter` passes these hints on to the `ImageConsumer`.

### setPixels

#### void setPixels (int x, int y, int width, int height, ColorModel model, byte[] pixels, int offset, int scansize)

Parameters

  x

    x-coordinate of top-left corner of pixel data delivered with this method call.

  y

    y-coordinate of top-left corner of pixel data delivered with this method call.

  width

    Width of the rectangle of pixel data delivered with this method call.

  height

    Height of the rectangle of pixel data delivered with this method call.

  model

    Color model of image data.

  pixels

    Image data.

  offset

    Offset from beginning of the pixels array.

  scansize

    Size of each line of data in pixels array.

Implements

  `ImageConsumer.setPixels(``int, int, int, int, ColorModel, byte[], int, int``)`

Description

  Delivers a rectangular block of pixels to the `ImageFilter`. `ImageFilter` passes these pixels on to the consumer unchanged.

#### void setPixels (int x, int y, int width, int height, ColorModel model, int[] pixels, int offset, int scansize)

Parameters

  x

    x-coordinate of top-left corner of pixel data delivered with this method call.

  y

    y-coordinate of top-left corner of pixel data delivered with this method call.

  width

    Width of the rectangle of pixel data delivered with this method call.

  height

    Height of the rectangle of pixel data delivered with this method call.

  model

    Color model of image data.

  pixels

    Image data.

  offset

    Offset from beginning of the pixels array.

  scansize

    Size of each line of data in pixels array.

Implements

  `ImageConsumer.setPixels(``int, int, int, int, ColorModel, int[], int, int``)`

Description

  Delivers a rectangular block of pixels to the `ImageFilter`. `ImageFilter` passes these pixels on to the consumer unchanged.

### setProperties

#### void setProperties (Hashtable properties)

Parameters

  properties

    The properties for the image.

Implements

  `ImageConsumer.setProperties(``Hashtable``)`

Description

  Initializes the image's properties. `ImageFilter` adds the property "filter" to the `Hashtable`, and passes the result on to the image consumer; the value of the property is the string returned by the filter's `toString()` method. If the property "filter" is already in the `Hashtable`, `ImageFilter` adds the string returned by its `toString()` method to the value already associated with that property.

## See Also

`Cloneable`, `ColorModel`, `CropImageFilter`, `Hashtable`, `ImageConsumer`, `ImageProducer`, `Object`, `ReplicateImageFilter`, `RGBImageFilter`

ImageConsumer |  | ImageObserver