Chapter 29

Packages java.awt image


CONTENTS


Although nearly all of the java.awt package consisted of graphical user interface components to be used for screen layout, the java.awt.image package contains classes that provide functionality for various image transformations and operations. The key interfaces within this package are the ImageConsumer and ImageProducer interfaces because they define the behavior for consumers and producers of images. Table 29.1 shows the contents of the java.awt.image package and Figure 29.1 shows its contents graphically.

Figure 29.1: The contents of package java.awt.image.

Table 29.1. Contents of package java.awt.image.

Class IndexInterface Index
ColorModel ImageConsumer
CropImageFilter ImageObserver
DirectColorModel ImageProducer
FilteredImageSource  
ImageFilter  
IndexColorModel  
MemoryImageSource  
PixelGrabber  
RGBImageFilter  

ColorModel

Object

The class hierarchy for the ColorModel class derives from class java.lang.Object. The ColorModel class is an abstract class that provides functions for translating pixel values into RGB color values. ColorModel's overall derivation can be seen in Figure 29.1.

Listing 29.1 shows the declarations for all of the public methods included in the java.awt.image.ColorModel class.


Listing 29.1. Public members of java.awt.image.ColorModel.
public abstract class ColorModel {
  public static ColorModel getRGBdefault()
  public ColorModel(int bits)
  public int getPixelSize()
  public abstract int getRed(int pixel)
  public abstract int getGreen(int pixel)
  public abstract int getBlue(int pixel)
  public abstract int getAlpha(int pixel)
  public int getRGB(int pixel)
  public void finalize()
}

ColorModel

ColorModel

public ColorModel(int bits)

The ColorModel() constructor constructs a color model that describes a pixel of the specified number of bits.

bits is an integer value containing the number of bits that will describe a pixel using this ColorModel.

GetRGBdefault

ColorModel

public static ColorModel getRGBdefault()

The getRGBdefault() method returns the default ColorModel that is used throughout all AWT image interfaces. This default ColorModel uses a pixel format that encapsulates alpha, red, green, and blue color values (eight bits each), using the following methodology: 0xAARRGGBB.

A ColorModel object representing the default color model for all AWT image interfaces.

GetPixelSize

ColorModel

public int getPixelSize()

The getPixelSize() method returns the size of the ColorModel's pixel.

An integer value representing the number of bits that make up a pixel in this ColorModel.

GetRed

ColorModel

public abstract int getRed(int pixel)

The getRed() method returns the red component of the specified pixel.

pixel is an integer containing the pixel representation for this color model.

An integer value representing the red component of the pixel.

GetGreen

ColorModel

public abstract int getGreen(int pixel)

The getGreen() method returns the green component of the specified pixel.

pixel is an integer containing the pixel representation for this color model.

An integer value representing the green component of the pixel.

GetBlue

ColorModel

public abstract int getBlue(int pixel)

The getBlue() method returns the blue component of the specified pixel.

pixel is an integer containing the pixel representation for this color model.

An integer value representing the blue component of the pixel.

GetAlpha

ColorModel

public abstract int getAlpha(int pixel)

The getAlpha() method returns the alpha component of the specified pixel.

pixel is an integer containing the pixel representation for this color model.

An integer value representing the alpha component of the pixel.

GetRGB

ColorModel

public int getRGB(int pixel)

The getRGB() method returns the RGB value of the pixel using the default color model.

pixel is an integer containing the pixel representation for this color model.

An integer value representing the RGB value of the pixel using the default color model.

Finalize

ColorModel

public void finalize()

The finalize() method is used to clean up internal data allocated by the ColorModel.

The finalize() method does not return a value.

CropImageFilter

ImageFilter

The class hierarchy for the CropImageFilter class derives from class java.awt.image.ImageFilter. The CropImageFilter class provides the ability to extract a rectangular subset of a given image (cropping it). This class is used in conjunction with a FilteredImageSource class to provide a source for the cropped image. CropImageFilter's overall derivation can be seen in Figure 29.1.

Listing 29.2 shows the declarations for all of the public methods included in the java.awt.image.CropImageFilter class.


Listing 29.2. Public members of java.awt.image.CropImageFilter.
public class CropImageFilter extends ImageFilter {
  public CropImageFilter(int x, int y, int w, int h)
public void setProperties(Hashtable props)
  public void setDimensions(int w, int h)
public void setPixels(int x, int y, int w, int h,
                          ColorModel model, byte pixels[], int off,
int scansize)
  public void setPixels(int x, int y, int w, int h,
ColorModel model, int pixels[], int off,
                          int scansize)
}

CropImageFilter

CropImageFilter

public CropImageFilter(int x, int y, int w, int h)

The CropImageFilter() constructor constructs a CropImageFilter to crop an image using a cropping rectangle. The dimensions of this rectangle are specified using the following parameters.

x is the top x coordinate of the cropping rectangle containing the image.

y is the top y coordinate of the cropping rectangle containing the image.

w is the width of the rectangular cropping area.

h is the height of the rectangular cropping area.

SetProperties

CropImageFilter

public void setProperties(Hashtable props)

The setProperties() method takes the props parameter from a source object and adds the croprect property to it to identify the region being cropped.

props is a Hashtable object containing properties from the source object.

setProperties() in class ImageFilter.

SetDimensions

CropImageFilter

public void setDimensions(int w, int h)

The setDimensions() method overrides the source's dimensions and passes the dimensions of the cropped region to the ImageConsumer interface.

w is the width value in pixels.

h is the height value in pixels.

setDimensions() in class ImageFilter.

SetPixels

CropImageFilter

public void setPixels(int x, int y, int w, int h, ColorModel model,
 byte pixels[], int off, int scansize)

The setPixels() method filters the pixels array by determining which pixels lie in the cropped region. Those that do are passed on to the Consumer interface.

x is the x coordinate of the image.
y is the y coordinate of the image.
w is the width of the image.
h is the height of the image.
model is the ColorModel that the pixels array conforms to.
pixels is a byte array containing pixels to be examined.
off is a variable that is passed on to the ImageConsumer's setPixels() method. For more information, see the ImageConsumer interface documentation later in this chapter.
scansize is an integer value representing the scansize of the operation.
setPixels() in class ImageFilter.

SetPixels

CropImageFilter

public void setPixels(int x, int y, int w, int h, ColorModel model,
 int pixels[], int off, int scansize)

The setPixels() method filters the pixels array by determining which pixels lie in the cropped region. Those that do are passed on to the Consumer interface.

x is the x coordinate of the image.

y is the y coordinate of the image.

w is the width of the image.

h is the height of the image.

model is the ColorModel that the pixels array conforms to.

pixels is an array of integers containing pixels to be examined.

off is a variable that is passed on to the ImageConsumer's setPixels() method. For more information, see the ImageConsumer interface documentation later in this chapter.

scansize is an integer value representing the scansize of the operation.

setPixels() in class ImageFilter.

DirectColorModel

ColorModel

The class hierarchy for the DirectColorModel class derives from class java.awt.image.ColorModel. The DirectColorModel class specifies translations from pixel values to RGB color values for pixels that have the colors embedded directly in the pixel bits. The DirectColorModel's overall derivation can be seen in Figure 29.1.

Listing 29.3 shows the declarations for all of the public methods included in the java.awt.image.DirectColorModel class.


Listing 29.3. Public members of java.awt.image.DirectColorModel.
public class DirectColorModel extends ColorModel {
  public DirectColorModel(int bits, int rmask, int gmask, int bmask)
  public DirectColorModel(int bits, int rmask, int gmask, int bmask, int amask)
  final public int getRedMask()
  final public int getGreenMask()
  final public int getBlueMask()
  final public int getAlphaMask()
  final public int getRed(int pixel)
  final public int getGreen(int pixel)
  final public int getBlue(int pixel)
  final public int getAlpha(int pixel)
  final public int getRGB(int pixel)
}

DirectColorModel

DirectColorModel

public DirectColorModel(int bits, int rmask, int gmask, int bmask)

The DirectColorModel() constructor constructs a DirectColorModel using the specified parameters. DirectColorModels built using this constructor have a default alpha mask value of 255. An alpha mask is a value used to interpolate between the each color value when two figures are overlaid.

Bits is the number of bits used to represent a pixel.

rmask is the number of bits required to represent the red component.

gmask is the number of bits required to represent the green component.

bmask is the number of bits required to represent the blue component.

DirectColorModel

DirectColorModel

public DirectColorModel(int bits, int rmask, int gmask, int bmask, int amask)

The DirectColorModel() constructor constructs a DirectColorModel using the specified parameters.

bits is the number of bits used to represent a pixel.

rmask is the number of bits required to represent the red component.

gmask is the number of bits required to represent the green component.

bmask is the number of bits required to represent the blue component.

amask is the number of bits required to represent the alpha component.

GetRedMask

DirectColorModel

final public int getRedMask()

The getRedMask() method returns the current red mask value.

An integer value representing the red mask value.

GetGreenMask

DirectColorModel

final public int getGreenMask()

The getGreenMask() method returns the current green mask value.

An integer value representing the green mask value.

GetBlueMask

DirectColorModel

final public int getBlueMask()

The getBlueMask() method returns the current blue mask value.

An integer value representing the blue mask value.

GetAlphaMask

DirectColorModel

final public int getAlphaMask()

The getAlphaMask() method returns the current alpha mask value.

An integer value representing the alpha mask value.

GetRed

DirectColorModel

final public int getRed(int pixel)

The getRed() method returns the red component for the specified pixel in the range 0-255.

pixel is an integer value representing a pixel under the DirectColorModel.

An integer value representing the red component of the pixel.

GetGreen

DirectColorModel

final public int getGreen(int pixel)

The getGreen() method returns the green component for the specified pixel in the range 0-255.

pixel is an integer value representing a pixel under the DirectColorModel.

An integer value representing the green component of the pixel.

GetBlue

DirectColorModel

final public int getBlue(int pixel)

The getBlue() method returns the blue component for the specified pixel in the range 0-255.

pixel is an integer value representing a pixel under the DirectColorModel.

An integer value representing the blue component of the pixel.

GetAlpha

DirectColorModel

final public int getAlpha(int pixel)

The getAlpha() method returns the alpha component for the specified pixel in the range 0-255.

pixel is an integer value representing a pixel under the DirectColorModel.

An integer value representing the alpha component of the pixel.

GetRGB

DirectColorModel

final public int getRGB(int pixel)

The getRGB() method returns the RGB color value for the specified pixel in the range 0-255.

pixel is an integer value representing a pixel under the DirectColorModel.

An integer value representing the RGB color value of the pixel using the default RGB color model.

FilteredImageSource

Object

ImageProducer

The class hierarchy for the FilteredImageSource class derives from class java.lang.Object. The FilteredImageSource takes as input an existing image and a filter object. It applies the filter to the image to produce a new version of the original image. The FilteredImageSource class implements the ImageProducer interface. FilteredImageSource's overall derivation can be seen in Fig- ure 29.1.

Listing 29.4 shows the declarations for all of the public methods included in the java.awt.image.FilteredImageSource class.


Listing 29.4. Public members of java.awt.image.FilteredImageSource.
public class FilteredImageSource implements ImageProducer {
  public FilteredImageSource(ImageProducer orig, ImageFilter imgf)
  public synchronized void addConsumer(ImageConsumer ic)
  public synchronized boolean isConsumer(ImageConsumer ic)
  public synchronized void removeConsumer(ImageConsumer ic)
  public void startProduction(ImageConsumer ic)
  public void requestTopDownLeftRightResend(ImageConsumer ic)
}

FilteredImageSource

FilteredImageSource

public FilteredImageSource(ImageProducer orig, ImageFilter imgf)

The FilteredImageSource() constructor constructs a FilteredImageSource object, which takes a producer source and an ImageFilter to produce a filtered version of the image.

Orig is an ImageProducer interface that supplies the image source.

Imgf is an ImageFilter that filters the image to produce a new image.

AddConsumer

FilteredImageSource

public synchronized void addConsumer(ImageConsumer ic)

The addConsumer() method adds an ImageConsumer interface to a list of consumers interested in image data.

ic is an ImageConsumer interface to be added to a listof ImageConsumers.

IsConsumer

FilteredImageSource

public synchronized boolean isConsumer(ImageConsumer ic)

The isConsumer() method determines whether the specified ImageConsumer is currently on the list of ImageConsumers for the image data.

ic is an ImageConsumer interface to be used for the check.

A Boolean value that is true if the specified ImageConsumer is on the list, false if not.

RemoveConsumer

FilteredImageSource

public synchronized void removeConsumer(ImageConsumer ic)

The removeConsumer() method removes the specified ImageConsumer from the list of ImageConsumers.

ic is the ImageConsumer interface to be removed from the list.

StartProduction

FilteredImageSource

public void startProduction(ImageConsumer ic)

The startProduction() method adds the specified ImageConsumer to the list of ImageConsumers and immediately starts delivery of the image data to the interface.

ic is the ImageConsumer that will be used to produce new image data.

RequestTopDownLeftRightResend

FilteredImageSource

public void requestTopDownLeftRightResend(ImageConsumer ic)

The requestTopDownLeftRightResend() method is used to deliver the image data to the specified ImageConsumer in top-down, left-right order.

ic is the ImageConsumer that will be the recipient of the image data when it is present.

ImageFilter

Object

ImageConsumer, Cloneable

The class hierarchy for the ImageFilter class derives from class java.lang.Object. The ImageFilter class acts as a base class for all image filtering classes. It implements the ImageConsumer and Cloneable interfaces. ImageFilter's overall derivation can be seen in Figure 29.1.

Listing 29.5 shows the declarations for all of the public methods included in the java.awt.image.ImageFilter class.


Listing 29.5. Public members of java.awt.image.ImageFilter.
public class ImageFilter implements ImageConsumer, Cloneable {
  public ImageFilter getFilterInstance(ImageConsumer ic)
  public void setDimensions(int width, int height}
  public void setProperties(Hashtable props)
  public void setColorModel(ColorModel model)
  public void setHints(int hints)
  public void setPixels(int x, int y, int w, int h, ColorModel model,
  
Âbyte pixels[], int off, int scansize)
  Public void setPixels(int x, int y, int w, int h, ColorModel model,
  
Âint pixels[], int off,  int scansize)
public void imageComplete(int status)
  public void resendTopDownLeftRight(ImageProducer ip)
  public Object clone()
}

getFilterInstance

ImageFilter

public ImageFilter getFilterInstance(ImageConsumer ic)

The getFilterInstance() method returns an ImageFilter object that will be used to perform the filtering for the specified ImageConsumer.

ic is the ImageConsumer that requires the image filtering.

An ImageFilter object to be used to perform the image filtering.

SetDimensions

ImageFilter

public void setDimensions(int width, int height}

The setDimensions() method filters the information provided in the setDimensions() method of the ImageConsumer interface.

width is the filter width.

height is the filter height.

SetProperties

ImageFilter

public void setProperties(Hashtable props)

The setProperties() method passes the props value along after a property is added that identifies which filters have been applied to the image.

props is a Hashtable object containing a set of properties. For more information on the Hashtable object, see the java.util package documentation in Chapter 34, "Package java.util."

setColorModel

ImageFilter

public void setColorModel(ColorModel model)

The setColorModel() method filters the information provided in the setColorModel() method of the ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

model is a ColorModel object.

SetHints

ImageFilter

public void setHints(int hints)

The setHints() method filters the information provided in the setHints() method of the ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

hints is an integer value containing hints.

SetPixels

ImageFilter

public void setPixels(int x, int y, int w, int h, ColorModel model,
 byte pixels[], int off, int scansize)

The setPixels() method filters the pixels array. The pixels that pass through the filter are passed onto the ImageConsumer interface.

x is the x coordinate of the image.

y is the y coordinate of the image.

w is the width of the image.

h is the height of the image.

model is the ColorModel that the pixels array conforms to.

pixels is a byte array containing pixels to be examined.

off is a variable that is passed on to the ImageConsumer's setPixels() method. For more information, see the ImageConsumer interface documentation later in this chapter.

scansize is an integer value representing the scansize of the operation.

SetPixels

ImageFilter

public void setPixels(int x, int y, int w, int h, ColorModel model,
 int pixels[], int off, int scansize

The setPixels() method filters the pixels array. The pixels that pass through the filter are passed onto the ImageConsumer interface.

x is the x coordinate of the image.

y is the y coordinate of the image.

w is the width of the image.

h is the height of the image.

model is the ColorModel that the pixels array conforms to.

pixels is an integer array containing pixels to be examined.

off is a variable that is passed onto the ImageConsumer's setPixels() method. For more information, see the ImageConsumer interface documentation later in this chapter.

scansize is an integer value representing the scansize of the operation.

ImageComplete

ImageFilter

public void imageComplete(int status)

The imageComplete() method filters the information provided by the imageComplete() method in the ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

status is an integer value representing the status of the filter operation.

ResendTopDownLeftRight

ImageFilter

public void resendTopDownLeftRight(ImageProducer ip)

The resendTopDownLeftRight() method is used to deliver the image data to the specified ImageConsumer in top-down, left-right order.

ip is the ImageProducer that is responsible for production of the image data.

Clone

ImageFilter

public Object clone()

The clone() method returns a clone of the ImageFilter.

An object that is identical to the ImageFilter.

IndexColorModel

ColorModel

The class hierarchy for the IndexColorModel class derives from class java.awt.image.ColorModel. This class translates from pixel values to RGB color values for pixels that represent indexes into a color map. The IndexColorModel class's overall derivation can be seen in Figure 29.1.

Listing 29.6 shows the declarations for all of the public methods included in the java.awt.image.IndexColorModel class.


Listing 29.6. Public members of java.awt.image.IndexColorModel.
public class IndexColorModel extends ColorModel {
  public IndexColorModel(int bits, int size, byte r[], byte g[], byte b[])
  public IndexColorModel(int bits, int size, byte r[], byte g[],
  
 byte b[], int trans)
public IndexColorModel(int bits, int size, byte r[], byte g[],
 byte b[], byte a[])
public IndexColorModel(int bits, int size, byte cmap[],
 int start, boolean hasalpha)
  public IndexColorModel(int bits, int size, byte cmap[],
  
 int start, boolean hasalpha, int trans)
final public int getMapSize()
  final public int getTransparentPixel()
  final public void getReds(byte r[])
  final public void getGreens(byte g[])
  final public void getBlues(byte b[])
  final public void getAlphas(byte a[])
  final public int getRed(int pixel)
  final public int getGreen(int pixel)
  final public int getBlue(int pixel)
  final public int getAlpha(int pixel)
  final public int getRGB(int pixel)
}

IndexColorModel

IndexColorModel

public IndexColorModel(int bits, int size, byte r[], byte g[], byte b[])

The IndexColorModel() constructor constructs a color model from the specified information.

bits is the number of bits required to represent a pixel.

size is the size of the color arrays.

r is the red color array.

g is the green color array.

b is the blue color array.

IndexColorModel

IndexColorModel

public IndexColorModel(int bits, int size, byte r[], byte g[],
 byte b[], int trans)

The IndexColorModel() constructor constructs a color model from the specified information.

bits is the number of bits required to represent a pixel.

size is the size of the color arrays.

r is the red color array.

g is the green color array.

b is the blue color array.

trans is an integer value representing the index that identifies the transparent pixel.

IndexColorModel

IndexColorModel

public IndexColorModel(int bits, int size, byte r[], byte g[],
 byte b[], byte a[])

The IndexColorModel() constructor constructs a color model from the specified information.

bits is the number of bits required to represent a pixel.

size is the size of the color arrays.

r is the red color array.

g is the green color array.

b is the blue color array.

a is the alpha color array.

IndexColorModel

IndexColorModel

public IndexColorModel(int bits, int size, byte cmap[],
 int start, boolean hasalpha)

The IndexColorModel() constructor constructs a color model from the specified information.

bits is the number of bits required to represent a pixel.

size is the size of the color arrays.

cmap is a byte array representing the color map array.

start is the index representing the first color component within the color array.

hasalpha is a Boolean value indicating whether alpha values are contained within the color map. This Boolean value will be true if alpha values are contained.

IndexColorModel

IndexColorModel

public IndexColorModel(int bits, int size, byte cmap[],
 int start, boolean hasalpha, int trans)

The IndexColorModel() constructor constructs a color model from the specified information.

bits is the number of bits required to represent a pixel.

size is the size of the color arrays.

cmap is a byte array representing the color map array.

start is the index representing the first color component within the color array.

hasalpha is a Boolean value indicating whether alpha values are contained within the color map. This Boolean value will be true if alpha values are contained.

trans is an integer value representing the index of the transparent pixel.

GetMapSize

IndexColorModel

final public int getMapSize()

The getMapSize() method returns the size of the color map used by the IndexColorModel.

An integer value representing the size of the color map used by the IndexColorModel.

GetTransparentPixel

IndexColorModel

final public int getTransparentPixel()

The getTransparentPixel() method returns the index into the color map of the transparent pixel.

An integer value representing the index into the color map of the transparent pixel. If there is no transparent pixel, this method returns -1.

GetReds

IndexColorModel

final public void getReds(byte r[])

The getReds() method fills the byte array with the red color components.

r is a byte array that is filled by the getReds() method with the red color components.

GetGreens

IndexColorModel

final public void getGreens(byte g[])

The getGreens() method fills the byte array with the green color components.

r is a byte array that is filled by the getGreens() method with the green color components.

GetBlues

IndexColorModel

final public void getBlues(byte b[])

The getBlues() method fills the byte array with the blue color components.

r is a byte array that is filled by the getBlues() method with the blue color components.

GetAlphas

IndexColorModel

final public void getAlphas(byte a[])

The getAlphas() method fills the byte array with the alpha components.

r is a byte array that is filled by the getAlphas() method with the alpha components.

GetRed

IndexColorModel

final public int getRed(int pixel)

The getRed() method returns the red color component for the specified pixel using the IndexColorModel.

pixel is an integer value representing a pixel.

An integer value in the range 0-255 representing the red component for the specified pixel.

GetGreen

IndexColorModel

final public int getGreen(int pixel)

The getGreen() method returns the green color component for the specified pixel using the IndexColorModel.

pixel is an integer value representing a pixel.

An integer value in the range 0-255 representing the green component for the specified pixel.

GetBlue

IndexColorModel

final public int getBlue(int pixel)

The getBlue() method returns the blue color component for the specified pixel using the IndexColorModel.

pixel is an integer value representing a pixel.

An integer value in the range 0-255 representing the blue component for the specified pixel.

GetAlpha

IndexColorModel

final public int getAlpha(int pixel)

The getAlpha() method returns the alpha color component for the specified pixel using the IndexColorModel.

pixel is an integer value representing a pixel.

An integer value in the range 0-255 representing the alpha component for the specified pixel.

GetRGB

IndexColorModel

final public int getRGB(int pixel)

The getRGB() method returns the RGB color value for the specified pixel using the default RGB color model.

pixel is an integer value representing a pixel.

An integer value in the range 0-255 representing the RGB color value for the specified pixel.

MemoryImageSource

Object

ImageProducer

The class hierarchy for the MemoryImageSource class derives from class java.lang.Object. This class uses an array to produce image pixel values. MemoryImageSource's overall derivation can be seen in Figure 29.1.

Listing 29.7 shows the declarations for all of the public methods included in the java.awt.image.MemoryImageSource class.


Listing 29.7. Public members of java.awt.image.MemoryImageSource.
public class MemoryImageSource implements ImageProducer {
  public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix,
 int off, int scan)
public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix,
 int off, int scan, Hashtable props)
public MemoryImageSource(int w, int h, ColorModel cm, int[] pix,
 int off, int scan)
public MemoryImageSource(int w, int h, ColorModel cm, int[] pix,
 int off, int scan, Hashtable props)
public MemoryImageSource(int w, int h, int pix[], int off, int scan)
public MemoryImageSource(int w, int h, int pix[], int off,
 int scan, Hashtable props)
public synchronized void addConsumer(ImageConsumer ic)
  public synchronized boolean isConsumer(ImageConsumer ic)
  public synchronized void removeConsumer(ImageConsumer ic)
  public void startProduction(ImageConsumer ic)
  public void requestTopDownLeftRightResend(ImageConsumer ic)
}

MemoryImageSource

MemoryImageSource

public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix,
 int off, int scan)

The MemoryImageSource() constructor uses an array of bytes to produce image data for an image object.

w is the width of the image to be created in pixels.

h is the height of the image to be created in pixels.

Cm is the color model used to translate the pixel values.

Pix is a byte array containing the image data.

Off is the offset into the array to begin reading.

scan is the scan value.

MemoryImageSource

MemoryImageSource

public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix,
 int off, int scan, Hashtable props)

The MemoryImageSource() constructor uses an array of bytes to produce image data for an image object.

w is the width of the image to be created in pixels.

h is the height of the image to be created in pixels.

cm is the color model used to translate the pixel values.

pix is a byte array containing the image data.

off is the offset into the array to begin reading.

scan is the scan value.

props is a Hashtable object containing properties to be used by the ImageProducer. For more information on the Hashtable class, see the java.util package documentation in Chapter 34.

MemoryImageSource

MemoryImageSource

public MemoryImageSource(int w, int h, ColorModel cm, int[] pix,
 int off, int scan)

The MemoryImageSource() constructor uses an array of bytes to produce image data for an image object.

w is the width of the image to be created in pixels.

h is the height of the image to be created in pixels.

cm is the color model used to translate the pixel values.

pix is an integer array containing the image data.

off is the offset into the array to begin reading.

scan is the scan value.

MemoryImageSource

MemoryImageSource

public MemoryImageSource(int w, int h, ColorModel cm, int[] pix,
 int off, int scan, Hashtable props)

The MemoryImageSource() constructor uses an array of bytes to produce image data for an image object.

w is the width of the image to be created in pixels.

h is the height of the image to be created in pixels.

cm is the color model used to translate the pixel values.

pix is an integer array containing the image data.

off is the offset into the array to begin reading.

scan is the scan value.

props is a Hashtable object containing properties to be used by the ImageProducer. For more information on the Hashtable class, see the java.util package documentation in Chapter 34.

MemoryImageSource

MemoryImageSource

public MemoryImageSource(int w, int h, int pix[], int off, int scan)

The MemoryImageSource() constructor uses an array of bytes to produce image data for an image object.

w is the width of the image to be created in pixels.

h is the height of the image to be created in pixels.

pix is an integer array containing the image data.

off is the offset into the array to begin reading.

scan is the scan value.

MemoryImageSource

MemoryImageSource

public MemoryImageSource(int w, int h, int pix[],
 int off, int scan, Hashtable props)

The MemoryImageSource() constructor uses an array of bytes to produce image data for an image object.

w is the width of the image to be created in pixels.

h is the height of the image to be created in pixels.

pix is an integer array containing the image data.

off is the offset into the array to begin reading.

scan is the scan value.

props is a Hashtable object containing properties to be used by the ImageProducer. For more information on the Hashtable class, see the java.util package documentation in Chapter 34.

AddConsumer

MemoryImageSource

public synchronized void addConsumer(ImageConsumer ic)

The addConsumer() method adds an ImageConsumer interface to a list of image consumers who are interested in data for the image.

ic is an ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

IsConsumer

MemoryImageSource

public synchronized boolean isConsumer(ImageConsumer ic)

The isConsumer() method determines if the specified ImageConsumer is currently in the list.

ic is an ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

A Boolean value that is true if the ImageConsumer is already in the list, false if not.

RemoveConsumer

MemoryImageSource

public synchronized void removeConsumer(ImageConsumer ic)

The removeConsumer() method removes the specified ImageConsumer from the list of image consumers interested in receiving image data.

ic is an ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

StartProduction

MemoryImageSource

public void startProduction(ImageConsumer ic)

The startProduction() method adds the specified ImageConsumer to a list of image consumers interested in receiving image data. This method also immediately starts production of image data to be sent to the ImageConsumer interfaces.

ic is an ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

RequestTopDownLeftRightResend

MemoryImageSource

public void requestTopDownLeftRightResend(ImageConsumer ic)

The requestTopDownLeftRightResend() method is used to deliver the image data to the specified ImageConsumer in top-down, left-right order.

ic is an ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

PixelGrabber

Object

ImageConsumer

The class hierarchy for the PixelGrabber class derives from class java.lang.Object. The PixelGrabber class implements the ImageConsumer interface to retrieve a subset of pixels from an Image. PixelGrabber's overall derivation can be seen in Figure 29.1.

Listing 29.8 shows the declarations for all of the public methods included in the java.awt.image.PixelGrabber class.


Listing 29.8. Public members of java.awt.image.PixelGrabber.
public class PixelGrabber implements ImageConsumer {
  public PixelGrabber(Image img, int x, int y, int w, int h, int[] pix,
  
 int off, int scansize)
public PixelGrabber(ImageProducer ip, int x, int y, int w, int h, int[] pix,
 int off, int scansize)
public boolean grabPixels() throws InterruptedException
  public synchronized boolean grabPixels(long ms) throws InterruptedException
  public synchronized int status()
  public void setDimensions(int width, int height)
  public void setHints(int hints)
  public void setProperties(Hashtable props)
  public void setColorModel(ColorModel model)
  public void setPixels(int srcX, int srcY, int srcW, int srcH,
  
 ColorModel model, byte pixels[], int srcOff, int srcScan)
  public void setPixels(int srcX, int srcY, int srcW, int srcH,
  
 ColorModel model, int pixels[], int srcOff, int srcScan)
  public synchronized void imageComplete(int status)
  }

PixelGrabber

PixelGrabber

public PixelGrabber(Image img, int x, int y, int w, int h, int[] pix,
 int off, int scansize)

The PixelGrabber() constructor constructs a PixelGrabber object to retrieve a subset of pixels from the Image. In this case, the PixelGrabber will grab a rectangular section of pixels.

img is an Image object to be "grabbed." For more information on the Image class, see the documentation earlier in this chapter.

x is the x coordinate at which to begin grabbing pixels.

y is the y coordinate at which to begin grabbing pixels.

w is the width of the PixelGrabber bounding rectangle.

h is the height of the PixelGrabber bounding rectangle.

pix is an array of integers used to store the grabbed pixels.

off is the offset into the Image to begin calculations.

scan is an integer value used to represent the scan size.

PixelGrabber

PixelGrabber

public PixelGrabber(ImageProducer ip, int x, int y, int w, int h, int[] pix,
 int off, int scansize)

The PixelGrabber() constructor constructs a PixelGrabber object to retrieve a subset of pixels from the Image. In this case, the PixelGrabber will grab a rectangular section of pixels.

ip is an ImageProducer object to be "grabbed." For more information on the ImageProducer interface, see the documentation later in this chapter.

x is the x coordinate at which to begin grabbing pixels.

y is the y coordinate at which to begin grabbing pixels.

w is the width of the PixelGrabber bounding rectangle.

h is the height of the PixelGrabber bounding rectangle.

pix is an array of integers used to store the grabbed pixels.

off is the offset into the Image to begin calculations.

scan is an integer value used to represent the scan size.

GrabPixels

PixelGrabber

public boolean grabPixels() throws InterruptedException

The grabPixels() method notifies the PixelGrabber to begin grabbing pixels and wait until all of the pixels to be grabbed have been delivered.

A Boolean value that is true if the operation was successful, false if not.

An InterruptedException if the process was interrupted.

GrabPixels

PixelGrabber

public synchronized boolean grabPixels(long ms) throws InterruptedException

This grabPixels() method notifies the PixelGrabber to begin grabbing pixels at some specified time in the future and wait until all of the pixels to be grabbed have been delivered.

ms is a long integer value representing the start time in milliseconds.

A Boolean value that is true if the operation was successful, false if not.

An InterruptedException if the process was interrupted.

Status

PixelGrabber

public synchronized int status()

The status() method returns a value representing the status of the grab operation.

An integer value representing the operation's status. This value will be a bitwise OR of all relevant ImageObserver flags.

SetDimensions

PixelGrabber

public void setDimensions(int width, int height)

The setDimensions() method must be implemented by this class to fulfill its interface with the ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

width is the width parameter.

height is the height parameter.

SetHints

PixelGrabber

public void setHints(int hints)

The setHints() method must be implemented by this class to fulfill its interface with the ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

hints is the hints parameter.

SetProperties

PixelGrabber

public void setProperties(Hashtable props)

The setProperties() method must be implemented by this class to fulfill its interface with the ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

props is a Hashtable object. For more information on the Hashtable class, see the java.util package documentation in Chapter 34.

SetColorModel

PixelGrabber

public void setColorModel(ColorModel model)

The setColorModel() method must be implemented by this class to fulfill the ImageConsumer interface. This interface is implemented by the PixelGrabber class to retrieve pixels. For more information on the ImageConsumer interface, see the documentation later in this chapter.

model is a ColorModel object. For more information on the ColorModel class, see the documentation earlier in this chapter.

SetPixels

PixelGrabber

public void setPixels(int srcX, int srcY, int srcW, int srcH,
 ColorModel model, byte pixels[], int srcOff, int srcScan)

The setPixels() method must be implemented by this class to fulfill the ImageConsumer interface. This interface must be implemented by the PixelGrabber class to retrieve its pixels. For more information on the ImageConsumer interface, see the documentation later in this chapter.

srcX is an integer value representing the source x coordinate.

srcY is an integer value representing the source y coordinate.

srcW is an integer value representing the source width.

srcH is an integer value representing the source height.

model is the ColorModel to be used.

pixels is a byte array of pixel values.

srcOff is the offset into the source array.

srcScan is the source scan value.

SetPixels

PixelGrabber

public void setPixels(int srcX, int srcY, int srcW, int srcH,
 ColorModel model, int pixels[], int srcOff, int srcScan)

The setPixels() method must be implemented by this class to fulfill ImageConsumer interface. This interface must be implemented by the PixelGrabber class to retrieve its pixels. For more information on the ImageConsumer interface, see the documentation later in this chapter.

srcX is an integer value representing the source x coordinate.

srcY is an integer value representing the source y coordinate.

srcW is an integer value representing the source width.

srcH is an integer value representing the source height.

model is the ColorModel to be used.

pixels is an integer array of pixel values.

srcOff is the offset into the source array.

srcScan is the source scan value.

ImageComplete

PixelGrabber

public synchronized void imageComplete(int status)

The imageComplete() method must be implemented by this class to fulfill its interface with the ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation later in this chapter.

status is an integer value representing the status of the pixel grab operation.

RGBImageFilter

ImageFilter

The class hierarchy for the RGBImageFilter class derives from class java.awt.image.ImageFilter. The RGBImageFilter abstract class provides the functionality to process image data within a single method that converts pixels in the default RGB ColorModel. RGBImageFilter's overall derivation can be seen in Figure 29.1.

Listing 29.9 shows the declarations for all of the public methods included in the java.awt.image.RGBImageFilter class.


Listing 29.9. Public members of java.awt.image.RGBImageFilter.
public abstract class RGBImageFilter extends ImageFilter {
  public void setColorModel(ColorModel model)
  public void substituteColorModel(ColorModel oldcm, ColorModel newcm)
  public IndexColorModel filterIndexColorModel(IndexColorModel icm)
  public void filterRGBPixels(int x, int y, int w, int h, int pixels[],
  
 int off, int scansize)
public void setPixels(int x, int y, int w, int h, ColorModel model,
 byte pixels[], int off, int scansize)
public void setPixels(int x, int y, int w, int h, ColorModel model,
 int pixels[], int off, int scansize)
public abstract int filterRGB(int x, int y, int rgb)
}

Setcolormodel

RGBImageFilter

public void setColorModel(ColorModel model)

The setColorModel() method checks the type of the specified ColorModel. If it is an IndexColorModel and the protected canFilterIndexColorModel variable is true, then the color model will be set to the IndexColorModel. Otherwise, the default RGB color model will be used for all filtering operations.

Model is the color model to be used for filtering.

SubstituteColorModel

RGBImageFilter

public void substituteColorModel(ColorModel oldcm, ColorModel newcm)

The substituteColorModel() method allows color models to be interchanged on-the-fly. If the old color model is encountered during a setPixels() method call, then the new color model will be used instead.

oldcm is the old color model to be replaced.

newcm is the new color model.

FilterIndexColorModel

RGBImageFilter

public IndexColorModel filterIndexColorModel(IndexColorModel icm)

The filterIndexColorModel() method runs each entry in the specified IndexColorModel through the filterRGB() method and returns a new color model.

icm is the IndexColorModel to be filtered.

An IndexColorModel that has been filtered by the RGBImageFilter class.

FilterRGBPixels

RGBImageFilter

public void filterRGBPixels(int x, int y, int w, int h, int pixels[],
 int off, int scansize)

The filterRGBPixels() method filters an array of pixels through the filterRGB() method.

x is the x coordinate at which to start the filtering.

y is the y coordinate at which to start the filtering.

w is the width of the image to be filtered.

h is the height of the image to be filtered.

pixels is an array of integers representing pixel values.

off is the offset used.

scansize is the scan size used.

SetPixels

RGBImageFilter

public void setPixels(int x, int y, int w, int h, ColorModel model,
 byte pixels[], int off, int scansize)

The setPixels() method converts the pixels and color model before passing them on. If the ColorModel has already been converted, the pixels are passed through with the converted ColorModel. If not, then the pixel array is converted to the default RGB color model using the filterRGBPixels() method.

x is the x coordinate at which to start the filtering.

y is the y coordinate at which to start the filtering.

w is the width of the image to be filtered.

h is the height of the image to be filtered.

model is the ColorModel with which the pixels comply.

pixels is an array of bytes representing pixel values.

off is the offset used.

scansize is the scan size used.

SetPixels

RGBImageFilter

public void setPixels(int x, int y, int w, int h, ColorModel model,
 int pixels[], int off, int scansize)

The setPixels() method converts the pixels and color model before passing them on. If the ColorModel has already been converted, the pixels are passed through with the converted ColorModel. If not, then the pixel array is converted to the default RGB color model using the filterRGBPixels() method.

x is the x coordinate to start the filtering at.

y is the y coordinate to start the filtering at.

w is the width of the image to be filtered.

h is the height of the image to be filtered.

model is the ColorModel that the pixels comply with.

pixels is an array of integers representing pixel values.

off is the offset used.

scansize is the scan size used.

FilterRGB

RGBImageFilter

public abstract int filterRGB(int x, int y, int rgb)

The filterRGB() method allows subclasses to specify a method that converts an input pixel using the default RGB color model to an output pixel.

x is the x coordinate of the pixel.

y is the y coordinate of the pixel.

rgb is the pixel value using the default RGB color model.

An integer value representing the filtered pixel value.

ImageConsumer

Object

The class hierarchy for the ImageConsumer interface extends from class java.lang.Object. This interface is implemented by objects that are responsible for acquiring data provided by the ImageProducer interface. ImageConsumer's overall derivation can be seen in Figure 29.1.

Listing 29.10 shows the declarations for all of the public methods and variables included in the java.awt.image.ImageConsumer interface.


Listing 29.10. Members of java.awt.image.ImageConsumer.
public interface ImageConsumer {
  void setDimensions(int width, int height)
  void setProperties(Hashtable props)
  void setColorModel(ColorModel model)
  void setHints(int hintflags)
  int RANDOMPIXELORDER
  int TOPDOWNLEFTRIGHT
  int COMPLETESCANLINES
  int SINGLEPASS
  int SINGLEFRAME
  int IMAGEERROR
  int SINGLEFRAMEDONE
  int STATICIMAGEDONE
  int IMAGEABORTED
  void setPixels(int x, int y, int w, int h, ColorModel model,
  
 byte pixels[], int off, int scansize)
void setPixels(int x, int y, int w, int h, ColorModel model,
 int pixels[], int off, int scansize)
void imageComplete(int status)
}

Instance Variables

The following instance variables are all declared as public static variables within the ImageConsumer interface. These variables are used to specify options to the ImageConsumer methods:

int RANDOMPIXELORDER

The pixels will be delivered in a random order.

int TOPDOWNLEFTRIGHT

The pixels will be delivered in top-down, left-right order.

int COMPLETESCANLINES

The pixels will be delivered in complete scan lines.

int SINGLEPASS

The pixels will be delivered in a single pass.

int SINGLEFRAME

The pixels will be delivered in a single frame.

int IMAGEERROR

An error occurred during image processing.

int SINGLEFRAMEDONE

A single frame is complete, but the overall operation has not been completed.

int STATICIMAGEDONE

The image construction is complete.

int IMAGEABORTED

The image creation was aborted.

SetDimensions

ImageConsumer

void setDimensions(int width, int height)

The setDimensions() method is used to report the dimensions of the source image to the ImageConsumer.

width is the width of the source image.

height is the height of the source image.

SetProperties

ImageConsumer

void setProperties(Hashtable props)

The setProperties() method is used to report the properties of the source image to the ImageConsumer.

props is a Hashtable object containing the image properties. For more information on the Hashtable class, see the java.util package documentation in Chapter 34.

SetColorModel

ImageConsumer

void setColorModel(ColorModel model)

The setColorModel() method is used to report the color model of the source image to the ImageConsumer.

model is the color model used by the source image. For more information on the ColorModel class, see the documentation earlier in this chapter.

SetHints

ImageConsumer

void setHints(int hintflags)

The setHints() method is used to report hints to the ImageConsumer. These hints are usually a bitmask of the ImageConsumer variables that are used to give information about the manner in which the pixels will be delivered.

hintflags is an integer value containing hints about the manner in which the pixels will be delivered.

SetPixels

ImageConsumer

void setPixels(int x, int y, int w, int h, ColorModel model,
 byte pixels[], int off, int scansize)

The setPixels() method is used to deliver the pixels to the ImageConsumer. Note: Pixel (m,n) is stored in the pixels array at index (n * scansize + m + off).

x is the x coordinate.

y is the y coordinate.

w is the width of the image.

h is the height of the image.

model is the ColorModel used.

pixels is an array of bytes containing pixel information.

off is the offset value.

scansize is the scan size value.

SetPixels

ImageConsumer

void setPixels(int x, int y, int w, int h, ColorModel model,
 int pixels[], int off, int scansize)

The setPixels() method is used to deliver the pixels to the ImageConsumer. Note: Pixel (m,n) is stored in the pixels array at index (n * scansize + m + off).

x is the x coordinate.

y is the y coordinate.

w is the width of the image.

h is the height of the image.

model is the ColorModel used.

pixels is an array of integers containing pixel information.

off is the offset value.

scansize is the scan size value.

ImageComplete

ImageConsumer

void imageComplete(int status)

The imageComplete() method is called when the ImageProducer is finished delivering an image frame. The ImageConsumer should remove itself from the ImageProducer's list at this time.

ImageObserver

Object

The class hierarchy for the ImageObserver interface extends from class java.lang.Object. This interface is implemented by objects that are responsible for receiving information about an image as it is being constructed. ImageObserver's overall derivation can be seen in Figure 29.1.

Listing 29.11 shows the declarations for all of the public methods included in the java.awt.image.ImageObserver interface.


Listing 29.11. Members of java.awt.image.ImageObserver.
public interface ImageObserver {
  public boolean imageUpdate(Image img, int infoflags, int x, int y,
  
 int width, int height)
public static final int WIDTH
  public static final int HEIGHT
  public static final int PROPERTIES
  public static final int SOMEBITS
  public static final int FRAMEBITS
  public static final int ALLBITS
  public static final int ERROR
  public static final int ABORT
}

Static Instance Variables

The following instance variables are all declared as public static variables within the ImageObserver interface. These variables are used to specify options to the ImageObserver methods:

public static final int WIDTH

The width of the base image is now available.

public static final int HEIGHT

The height of the base image is now available.

public static final int PROPERTIES

The properties of the base image are now available.

public static final int SOMEBITS

Some bits of the image for drawing are now available.

public static final int FRAMEBITS

Another complete frame of a multiframe image is now available.

public static final int ALLBITS

A static image that was previously drawn is now complete and can be drawn again.

public static final int ERROR

An image that was being tracked asynchronously has encountered an error.

public static final int ABORT

An image that was beingq tracked was aborted before production completed.

ImageUpdate

ImageObserver

public boolean imageUpdate(Image img, int infoflags, int x, int y,
 int width, int height)

The imageUpdate() method is called every time image information becomes available. The recipient of the update messages is an ImageObserver object that has requested information about an image.

img is the image of interest.

infoflags are status flags indicating the progress of the image process.

x is the x coordinate that applies (if necessary).

y is the y coordinate that applies (if necessary).

width is the width of the image (if necessary).

height is the height of the image (if necessary).

ImageProducer

Object

The class hierarchy for the ImageProducer interface extends from class java.lang.Object. The ImageProducer interface is implemented by objects that produce images. Each image contains an ImageProducer. ImageProducer's overall derivation can be seen in Figure 29.1.

Listing 29.12 shows the declarations for all of the public methods included in the java.awt.image.ImageProducer interface.


Listing 29.12. Members of java.awt.image.ImageProducer.
public interface ImageProducer {
  public void addConsumer(ImageConsumer ic)
  public boolean isConsumer(ImageConsumer ic)
  public void removeConsumer(ImageConsumer ic)
  public void startProduction(ImageConsumer ic)
  public void requestTopDownLeftRightResend(ImageConsumer ic)
}

addConsumer

ImageProducer

public void addConsumer(ImageConsumer ic)

The addConsumer() method adds the ImageConsumer to a list to receive image data during reconstruction of the image.

ic is an ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation earlier in this chapter.

IsConsumer

ImageProducer

public boolean isConsumer(ImageConsumer ic)

The isConsumer() method determines if the specified ImageConsumer is currently on the ImageProducer's list of recipients.

ic is an ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation earlier in this chapter.

A Boolean value that is true if the ImageConsumer is registered, false if not.

RemoveConsumer

ImageProducer

public void removeConsumer(ImageConsumer ic)

The removeConsumer() method removes the specified ImageConsumer from the internal list.

ic is an ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation earlier in this chapter.

StartProduction

ImageProducer

public void startProduction(ImageConsumer ic)

The startProduction() method adds the specified ImageConsumer to the list of image data recipients and immediately begins production of the image data.

ic is an ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation earlier in this chapter.

RequestTopDownLeftRightResend

ImageProducer

public void requestTopDownLeftRightResend(ImageConsumer ic)

The requestTopDownLeftRightResend() method is used to deliver the image data to the specified ImageConsumer in top-down, left-right order.

ic is an ImageConsumer interface. For more information on the ImageConsumer interface, see the documentation earlier in this chapter.