APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.image

public Class Raster

extends Object
Class Inheritance
Known Direct Subclasses
java.awt.image.WritableRaster
Imports
java.awt.Rectangle, .Point, sun.awt.image.ByteInterleavedRaster, .ShortInterleavedRaster, .IntegerInterleavedRaster, .ByteBandedRaster, .ShortBandedRaster, .BytePackedRaster, .SunWritableRaster

A class representing a rectangular array of pixels. A Raster encapsulates a DataBuffer that stores the sample values and a SampleModel that describes how to locate a given sample value in a DataBuffer.

A Raster defines values for pixels occupying a particular rectangular area of the plane, not necessarily including (0, 0). The rectangle, known as the Raster's bounding rectangle and available by means of the getBounds method, is defined by minX, minY, width, and height values. The minX and minY values define the coordinate of the upper left corner of the Raster. References to pixels outside of the bounding rectangle may result in an exception being thrown, or may result in references to unintended elements of the Raster's associated DataBuffer. It is the user's responsibility to avoid accessing such pixels.

A SampleModel describes how samples of a Raster are stored in the primitive array elements of a DataBuffer. Samples may be stored one per data element, as in a PixelInterleavedSampleModel or BandedSampleModel, or packed several to an element, as in a SinglePixelPackedSampleModel or MultiPixelPackedSampleModel. The SampleModel is also controls whether samples are sign extended, allowing unsigned data to be stored in signed Java data types such as byte, short, and int.

Although a Raster may live anywhere in the plane, a SampleModel makes use of a simple coordinate system that starts at (0, 0). A Raster therefore contains a translation factor that allows pixel locations to be mapped between the Raster's coordinate system and that of the SampleModel. The translation from the SampleModel coordinate system to that of the Raster may be obtained by the getSampleModelTranslateX and getSampleModelTranslateY methods.

A Raster may share a DataBuffer with another Raster either by explicit construction or by the use of the createChild and createTranslatedChild methods. Rasters created by these methods can return a reference to the Raster they were created from by means of the getParent method. For a Raster that was not constructed by means of a call to createTranslatedChild or createChild, getParent will return null.

The createTranslatedChild method returns a new Raster that shares all of the data of the current Raster, but occupies a bounding rectangle of the same width and height but with a different starting point. For example, if the parent Raster occupied the region (10, 10) to (100, 100), and the translated Raster was defined to start at (50, 50), then pixel (20, 20) of the parent and pixel (60, 60) of the child occupy the same location in the DataBuffer shared by the two Rasters. In the first case, (-10, -10) should be added to a pixel coordinate to obtain the corresponding SampleModel coordinate, and in the second case (-50, -50) should be added.

The translation between a parent and child Raster may be determined by subtracting the child's sampleModelTranslateX and sampleModelTranslateY values from those of the parent.

The createChild method may be used to create a new Raster occupying only a subset of its parent's bounding rectangle (with the same or a translated coordinate system) or with a subset of the bands of its parent.

All constructors are protected. The correct way to create a Raster is to use one of the static create methods defined in this class. These methods create instances of Raster that use the standard Interleaved, Banded, and Packed SampleModels and that may be processed more efficiently than a Raster created by combining an externally generated SampleModel and DataBuffer.

See Also
java.awt.image.DataBuffer, java.awt.image.SampleModel, java.awt.image.PixelInterleavedSampleModel, java.awt.image.BandedSampleModel, java.awt.image.SinglePixelPackedSampleModel, java.awt.image.MultiPixelPackedSampleModel

Field Summary

Modifier and TypeField and Description
protected DataBuffer
dataBuffer

The DataBuffer that stores the image data.

protected int
height

The height of this Raster.

protected int
minX

The X coordinate of the upper-left pixel of this Raster.

protected int
minY

The Y coordinate of the upper-left pixel of this Raster.

protected int
numBands

The number of bands in the Raster.

protected int
numDataElements

The number of DataBuffer data elements per pixel.

protected Raster
parent

The parent of this Raster, or null.

protected SampleModel
sampleModel

The SampleModel that describes how pixels from this Raster are stored in the DataBuffer.

protected int
sampleModelTranslateX

The X translation from the coordinate space of the Raster's SampleModel to that of the Raster.

protected int
sampleModelTranslateY

The Y translation from the coordinate space of the Raster's SampleModel to that of the Raster.

protected int
width

The width of this Raster.

Constructor Summary

AccessConstructor and Description
protected
Raster(SampleModel
The SampleModel that specifies the layout
sampleModel
,
Point
The Point that specified the origin
origin
)

Constructs a Raster with the given SampleModel.

protected
Raster(SampleModel
The SampleModel that specifies the layout
sampleModel
,
DataBuffer
The DataBuffer that contains the image data
dataBuffer
,
Point
The Point that specifies the origin
origin
)

Constructs a Raster with the given SampleModel and DataBuffer.

protected
Raster(SampleModel
The SampleModel that specifies the layout
sampleModel
,
DataBuffer
The DataBuffer that contains the image data
dataBuffer
,
Rectangle
The Rectangle that specifies the image area
aRegion
,
Point
The Point that specifies the translation from SampleModel to Raster coordinates
sampleModelTranslate
,
Raster
The parent (if any) of this raster
parent
)

Constructs a Raster with the given SampleModel, DataBuffer, and parent.

Method Summary

Modifier and TypeMethod and Description
public static WritableRaster

Returns:

a WritableRaster object with the specified data type, width, height and number of bands.
createBandedRaster
(int
the data type for storing samples
dataType
,
int
the width in pixels of the image data
w
,
int
the height in pixels of the image data
h
,
int
the number of bands
bands
,
Point
the upper-left corner of the Raster
location
)

Creates a Raster based on a BandedSampleModel with the specified data type, width, height, and number of bands.

public static WritableRaster

Returns:

a WritableRaster object with the specified data type, width, height, scanline stride, bank indices and band offsets.
createBandedRaster
(int
the data type for storing samples
dataType
,
int
the width in pixels of the image data
w
,
int
the height in pixels of the image data
h
,
int
the line stride of the image data
scanlineStride
,
int[]
the bank indices for each band
bankIndices
,
int[]
the offsets of all bands
bandOffsets
,
Point
the upper-left corner of the Raster
location
)

Creates a Raster based on a BandedSampleModel with the specified data type, width, height, scanline stride, bank indices and band offsets.

public static WritableRaster

Returns:

a WritableRaster object with the specified DataBuffer, width, height, scanline stride, bank indices and band offsets.
createBandedRaster
(DataBuffer
the DataBuffer that contains the image data
dataBuffer
,
int
the width in pixels of the image data
w
,
int
the height in pixels of the image data
h
,
int
the line stride of the image data
scanlineStride
,
int[]
the bank indices for each band
bankIndices
,
int[]
the offsets of all bands
bandOffsets
,
Point
the upper-left corner of the Raster
location
)

Creates a Raster based on a BandedSampleModel with the specified DataBuffer, width, height, scanline stride, bank indices, and band offsets.

public Raster

Returns:

a new Raster.
createChild
(int
The X coordinate of the upper-left corner in this Raster's coordinates
parentX
,
int
The Y coordinate of the upper-left corner in this Raster's coordinates
parentY
,
int
Width of the region starting at (parentX, parentY)
width
,
int
Height of the region starting at (parentX, parentY).
height
,
int
The X coordinate of the upper-left corner of the returned Raster
childMinX
,
int
The Y coordinate of the upper-left corner of the returned Raster
childMinY
,
int[]
Array of band indices, or null to use all bands
bandList
)

Returns a new Raster which shares all or part of this Raster's DataBuffer.

public WritableRaster

Returns:

a compatible WritableRaster with the same sample model and a new data buffer.
createCompatibleWritableRaster
()

Create a compatible WritableRaster the same size as this Raster with the same SampleModel and a new initialized DataBuffer.

public WritableRaster

Returns:

a compatible WritableRaster with the specified size and a new sample model and data buffer.
createCompatibleWritableRaster
(int
the specified width of the new WritableRaster
w
,
int
the specified height of the new WritableRaster
h
)

Create a compatible WritableRaster with the specified size, a new SampleModel, and a new initialized DataBuffer.

public WritableRaster

Returns:

a compatible WritableRaster with the specified size and location and a new sample model and data buffer.
createCompatibleWritableRaster
(Rectangle
a Rectangle that specifies the size and location of the WritableRaster
rect
)

Create a compatible WritableRaster with location (minX, minY) and size (width, height) specified by rect, a new SampleModel, and a new initialized DataBuffer.

public WritableRaster

Returns:

a compatible WritableRaster with the specified size and location and a new sample model and data buffer.
createCompatibleWritableRaster
(int
the X coordinate of the upper-left corner of the WritableRaster
x
,
int
the Y coordinate of the upper-left corner of the WritableRaster
y
,
int
the specified width of the WritableRaster
w
,
int
the specified height of the WritableRaster
h
)

Create a compatible WritableRaster with the specified location (minX, minY) and size (width, height), a new SampleModel, and a new initialized DataBuffer.

public static WritableRaster

Returns:

a WritableRaster object with the specified data type, width, height and number of bands.
createInterleavedRaster
(int
the data type for storing samples
dataType
,
int
the width in pixels of the image data
w
,
int
the height in pixels of the image data
h
,
int
the number of bands
bands
,
Point
the upper-left corner of the Raster
location
)

Creates a Raster based on a PixelInterleavedSampleModel with the specified data type, width, height, and number of bands.

public static WritableRaster

Returns:

a WritableRaster object with the specified data type, width, height, scanline stride, pixel stride and band offsets.
createInterleavedRaster
(int
the data type for storing samples
dataType
,
int
the width in pixels of the image data
w
,
int
the height in pixels of the image data
h
,
int
the line stride of the image data
scanlineStride
,
int
the pixel stride of the image data
pixelStride
,
int[]
the offsets of all bands
bandOffsets
,
Point
the upper-left corner of the Raster
location
)

Creates a Raster based on a PixelInterleavedSampleModel with the specified data type, width, height, scanline stride, pixel stride, and band offsets.

public static WritableRaster

Returns:

a WritableRaster object with the specified DataBuffer, width, height, scanline stride, pixel stride and band offsets.
createInterleavedRaster
(DataBuffer
the DataBuffer that contains the image data
dataBuffer
,
int
the width in pixels of the image data
w
,
int
the height in pixels of the image data
h
,
int
the line stride of the image data
scanlineStride
,
int
the pixel stride of the image data
pixelStride
,
int[]
the offsets of all bands
bandOffsets
,
Point
the upper-left corner of the Raster
location
)

Creates a Raster based on a PixelInterleavedSampleModel with the specified DataBuffer, width, height, scanline stride, pixel stride, and band offsets.

public static WritableRaster

Returns:

a WritableRaster object with the specified data type, width, height, and band masks.
createPackedRaster
(int
the data type for storing samples
dataType
,
int
the width in pixels of the image data
w
,
int
the height in pixels of the image data
h
,
int[]
an array containing an entry for each band
bandMasks
,
Point
the upper-left corner of the Raster
location
)

Creates a Raster based on a SinglePixelPackedSampleModel with the specified data type, width, height, and band masks.

public static WritableRaster

Returns:

a WritableRaster object with the specified data type, width, height, number of bands, and bits per band.
createPackedRaster
(int
the data type for storing samples
dataType
,
int
the width in pixels of the image data
w
,
int
the height in pixels of the image data
h
,
int
the number of bands
bands
,
int
the number of bits per band
bitsPerBand
,
Point
the upper-left corner of the Raster
location
)

Creates a Raster based on a packed SampleModel with the specified data type, width, height, number of bands, and bits per band.

public static WritableRaster

Returns:

a WritableRaster object with the specified DataBuffer, width, height, scanline stride, and band masks.
createPackedRaster
(DataBuffer
the DataBuffer that contains the image data
dataBuffer
,
int
the width in pixels of the image data
w
,
int
the height in pixels of the image data
h
,
int
the line stride of the image data
scanlineStride
,
int[]
an array containing an entry for each band
bandMasks
,
Point
the upper-left corner of the Raster
location
)

Creates a Raster based on a SinglePixelPackedSampleModel with the specified DataBuffer, width, height, scanline stride, and band masks.

public static WritableRaster

Returns:

a WritableRaster object with the specified DataBuffer, width, height, and bits per pixel.
createPackedRaster
(DataBuffer
the DataBuffer that contains the image data
dataBuffer
,
int
the width in pixels of the image data
w
,
int
the height in pixels of the image data
h
,
int
the number of bits for each pixel
bitsPerPixel
,
Point
the upper-left corner of the Raster
location
)

Creates a Raster based on a MultiPixelPackedSampleModel with the specified DataBuffer, width, height, and bits per pixel.

public static Raster

Returns:

a Raster with the specified SampleModel, DataBuffer, and location.
createRaster
(SampleModel
the specified SampleModel
sm
,
DataBuffer
the specified DataBuffer
db
,
Point
the upper-left corner of the Raster
location
)

Creates a Raster with the specified SampleModel and DataBuffer.

public Raster

Returns:

a new Raster with the same size, SampleModel, and DataBuffer as this Raster, but with the specified location.
createTranslatedChild
(int
the X coordinate of the upper-left corner of the new Raster
childMinX
,
int
the Y coordinate of the upper-left corner of the new Raster
childMinY
)

Create a Raster with the same size, SampleModel and DataBuffer as this one, but with a different location.

public static WritableRaster

Returns:

a WritableRaster with the specified SampleModel and location.
createWritableRaster
(SampleModel
the specified SampleModel
sm
,
Point
the upper-left corner of the WritableRaster
location
)

Creates a WritableRaster with the specified SampleModel.

public static WritableRaster

Returns:

a WritableRaster with the specified SampleModel, DataBuffer, and location.
createWritableRaster
(SampleModel
the specified SampleModel
sm
,
DataBuffer
the specified DataBuffer
db
,
Point
the upper-left corner of the WritableRaster
location
)

Creates a WritableRaster with the specified SampleModel and DataBuffer.

public Rectangle

Returns:

the bounding box of this Raster.
getBounds
()

Returns the bounding Rectangle of this Raster.

public DataBuffer

Returns:

the DataBuffer of this Raster.
getDataBuffer
()

Returns the DataBuffer associated with this Raster.

public Object

Returns:

An object reference to an array of type defined by getTransferType() with the requested pixel data.
getDataElements
(int
The X coordinate of the pixel location
x
,
int
The Y coordinate of the pixel location
y
,
Object
An object reference to an array of type defined by getTransferType() and length getNumDataElements(). If null, an array of appropriate type and size will be allocated
outData
)

Returns data for a single pixel in a primitive array of type TransferType.

public Object

Returns:

An object reference to an array of type defined by getTransferType() with the requested pixel data.
getDataElements
(int
The X coordinate of the upper-left pixel location
x
,
int
The Y coordinate of the upper-left pixel location
y
,
int
Width of the pixel rectangle
w
,
int
Height of the pixel rectangle
h
,
Object
An object reference to an array of type defined by getTransferType() and length w*h*getNumDataElements(). If null, an array of appropriate type and size will be allocated.
outData
)

Returns the pixel data for the specified rectangle of pixels in a primitive array of type TransferType.

public final int

Returns:

the height of this Raster.
getHeight
()

Returns the height in pixels of the Raster.

public final int

Returns:

the minimum x coordinate of this Raster.
getMinX
()

Returns the minimum valid X coordinate of the Raster.

public final int

Returns:

the minimum y coordinate of this Raster.
getMinY
()

Returns the minimum valid Y coordinate of the Raster.

public final int

Returns:

the number of bands of this Raster.
getNumBands
()

Returns the number of bands (samples per pixel) in this Raster.

public final int

Returns:

the number of data elements.
getNumDataElements
()

Returns the number of data elements needed to transfer one pixel via the getDataElements and setDataElements methods.

public Raster

Returns:

the parent Raster or null.
getParent
()

Returns the parent Raster (if any) of this Raster or null.

public int[]

Returns:

the samples for the specified pixel.
getPixel
(int
The X coordinate of the pixel location
x
,
int
The Y coordinate of the pixel location
y
,
int[]
An optionally preallocated int array
iArray
)

Returns the samples in an array of int for the specified pixel.

public float[]

Returns:

the samples for the specified pixel.
getPixel
(int
The X coordinate of the pixel location
x
,
int
The Y coordinate of the pixel location
y
,
float[]
An optionally preallocated float array
fArray
)

Returns the samples in an array of float for the specified pixel.

public double[]

Returns:

the samples for the specified pixel.
getPixel
(int
The X coordinate of the pixel location
x
,
int
The Y coordinate of the pixel location
y
,
double[]
An optionally preallocated double array
dArray
)

Returns the samples in an array of double for the specified pixel.

public int[]

Returns:

the samples for the specified rectangle of pixels.
getPixels
(int
The X coordinate of the upper-left pixel location
x
,
int
The Y coordinate of the upper-left pixel location
y
,
int
Width of the pixel rectangle
w
,
int
Height of the pixel rectangle
h
,
int[]
An optionally pre-allocated int array
iArray
)

Returns an int array containing all samples for a rectangle of pixels, one sample per array element.

public float[]

Returns:

the samples for the specified rectangle of pixels.
getPixels
(int
The X coordinate of the pixel location
x
,
int
The Y coordinate of the pixel location
y
,
int
Width of the pixel rectangle
w
,
int
Height of the pixel rectangle
h
,
float[]
An optionally pre-allocated float array
fArray
)

Returns a float array containing all samples for a rectangle of pixels, one sample per array element.

public double[]

Returns:

the samples for the specified rectangle of pixels.
getPixels
(int
The X coordinate of the upper-left pixel location
x
,
int
The Y coordinate of the upper-left pixel location
y
,
int
Width of the pixel rectangle
w
,
int
Height of the pixel rectangle
h
,
double[]
An optionally pre-allocated double array
dArray
)

Returns a double array containing all samples for a rectangle of pixels, one sample per array element.

public int

Returns:

the sample in the specified band for the pixel at the specified coordinate.
getSample
(int
The X coordinate of the pixel location
x
,
int
The Y coordinate of the pixel location
y
,
int
The band to return
b
)

Returns the sample in a specified band for the pixel located at (x,y) as an int.

public double

Returns:

the sample in the specified band for the pixel at the specified coordinate.
getSampleDouble
(int
The X coordinate of the pixel location
x
,
int
The Y coordinate of the pixel location
y
,
int
The band to return
b
)

Returns the sample in a specified band for a pixel located at (x,y) as a double.

public float

Returns:

the sample in the specified band for the pixel at the specified coordinate.
getSampleFloat
(int
The X coordinate of the pixel location
x
,
int
The Y coordinate of the pixel location
y
,
int
The band to return
b
)

Returns the sample in a specified band for the pixel located at (x,y) as a float.

public SampleModel

Returns:

the SampleModel of this Raster.
getSampleModel
()

Returns the SampleModel that describes the layout of the image data.

public final int

Returns:

the X translation from the coordinate space of the Raster's SampleModel to that of the Raster.
getSampleModelTranslateX
()

Returns the X translation from the coordinate system of the SampleModel to that of the Raster.

public final int

Returns:

the Y translation from the coordinate space of the Raster's SampleModel to that of the Raster.
getSampleModelTranslateY
()

Returns the Y translation from the coordinate system of the SampleModel to that of the Raster.

public int[]

Returns:

the samples for the specified band for the specified rectangle of pixels.
getSamples
(int
The X coordinate of the upper-left pixel location
x
,
int
The Y coordinate of the upper-left pixel location
y
,
int
Width of the pixel rectangle
w
,
int
Height of the pixel rectangle
h
,
int
The band to return
b
,
int[]
An optionally pre-allocated int array
iArray
)

Returns the samples for a specified band for the specified rectangle of pixels in an int array, one sample per array element.

public float[]

Returns:

the samples for the specified band for the specified rectangle of pixels.
getSamples
(int
The X coordinate of the upper-left pixel location
x
,
int
The Y coordinate of the upper-left pixel location
y
,
int
Width of the pixel rectangle
w
,
int
Height of the pixel rectangle
h
,
int
The band to return
b
,
float[]
An optionally pre-allocated float array
fArray
)

Returns the samples for a specified band for the specified rectangle of pixels in a float array, one sample per array element.

public double[]

Returns:

the samples for the specified band for the specified rectangle of pixels.
getSamples
(int
The X coordinate of the upper-left pixel location
x
,
int
The Y coordinate of the upper-left pixel location
y
,
int
Width of the pixel rectangle
w
,
int
Height of the pixel rectangle
h
,
int
The band to return
b
,
double[]
An optionally pre-allocated double array
dArray
)

Returns the samples for a specified band for a specified rectangle of pixels in a double array, one sample per array element.

public final int

Returns:

this transfer type.
getTransferType
()

Returns the TransferType used to transfer pixels via the getDataElements and setDataElements methods.

public final int

Returns:

the width of this Raster.
getWidth
()

Returns the width in pixels of the Raster.

private static native void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait