java.awt.image

Class Raster

public class Raster extends Object

A rectangular collection of pixels composed from a {@link DataBuffer} which stores the pixel values, and a {@link SampleModel} which is used to retrieve the pixel values.
Field Summary
protected DataBufferdataBuffer
The data buffer used to store the pixel values.
protected intheight
The height of the raster.
protected intminX
The x-coordinate of the top left corner of the raster.
protected intminY
The y-coordinate of the top left corner of the raster.
protected intnumBands
The number of bands.
protected intnumDataElements
protected Rasterparent
The raster's parent.
protected SampleModelsampleModel
The sample model used to access the pixel values.
protected intsampleModelTranslateX
protected intsampleModelTranslateY
protected intwidth
The width of the raster.
Constructor Summary
protected Raster(SampleModel sampleModel, Point origin)
Creates a new raster.
protected Raster(SampleModel sampleModel, DataBuffer dataBuffer, Point origin)
Creates a new raster.
protected Raster(SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion, Point sampleModelTranslate, Raster parent)
Creates a new raster.
Method Summary
static WritableRastercreateBandedRaster(int dataType, int w, int h, int bands, Point location)
Creates a new banded raster.
static WritableRastercreateBandedRaster(int dataType, int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location)
Creates a new banded raster.
static WritableRastercreateBandedRaster(DataBuffer dataBuffer, int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location)
Creates a new banded raster.
RastercreateChild(int parentX, int parentY, int width, int height, int childMinX, int childMinY, int[] bandList)
WritableRastercreateCompatibleWritableRaster()
Creates a new writable raster that is compatible with this raster.
WritableRastercreateCompatibleWritableRaster(int w, int h)
Creates a new writable raster that is compatible with this raster.
WritableRastercreateCompatibleWritableRaster(Rectangle rect)
Creates a new writable raster that is compatible with this raster, with the specified bounds.
WritableRastercreateCompatibleWritableRaster(int x, int y, int w, int h)
Creates a new writable raster that is compatible with this raster, with the specified bounds.
static WritableRastercreateInterleavedRaster(int dataType, int w, int h, int bands, Point location)
Creates an interleaved raster using the specified data type.
static WritableRastercreateInterleavedRaster(int dataType, int w, int h, int scanlineStride, int pixelStride, int[] bandOffsets, Point location)
Creates an interleaved raster.
static WritableRastercreateInterleavedRaster(DataBuffer dataBuffer, int w, int h, int scanlineStride, int pixelStride, int[] bandOffsets, Point location)
Creates a new interleaved raster.
static WritableRastercreatePackedRaster(int dataType, int w, int h, int[] bandMasks, Point location)
Creates a new packed raster.
static WritableRastercreatePackedRaster(int dataType, int w, int h, int bands, int bitsPerBand, Point location)
Creates a new raster.
static WritableRastercreatePackedRaster(DataBuffer dataBuffer, int w, int h, int scanlineStride, int[] bandMasks, Point location)
Creates a new packed raster.
static WritableRastercreatePackedRaster(DataBuffer dataBuffer, int w, int h, int bitsPerPixel, Point location)
Creates a new packed raster.
static RastercreateRaster(SampleModel sm, DataBuffer db, Point location)
Creates a new raster.
RastercreateTranslatedChild(int childMinX, int childMinY)
static WritableRastercreateWritableRaster(SampleModel sm, Point location)
Creates a new writable raster.
static WritableRastercreateWritableRaster(SampleModel sm, DataBuffer db, Point location)
Creates a new writable raster.
RectanglegetBounds()
Returns a new rectangle containing the bounds of this raster.
DataBuffergetDataBuffer()
Returns the data buffer that stores the pixel data for this raster.
ObjectgetDataElements(int x, int y, Object outData)
ObjectgetDataElements(int x, int y, int w, int h, Object outData)
intgetHeight()
Returns the height of the raster.
intgetMinX()
Returns the x-coordinate of the top left corner of the raster.
intgetMinY()
Returns the t-coordinate of the top left corner of the raster.
intgetNumBands()
Returns the number of bands for this raster.
intgetNumDataElements()
RastergetParent()
Returns the raster's parent.
int[]getPixel(int x, int y, int[] iArray)
Returns an array containing the samples for the pixel at (x, y) in the raster.
float[]getPixel(int x, int y, float[] fArray)
Returns an array containing the samples for the pixel at (x, y) in the raster.
double[]getPixel(int x, int y, double[] dArray)
Returns an array containing the samples for the pixel at (x, y) in the raster.
int[]getPixels(int x, int y, int w, int h, int[] iArray)
Returns an array containing the samples for the pixels in the region specified by (x, y, w, h) in the raster.
float[]getPixels(int x, int y, int w, int h, float[] fArray)
Returns an array containing the samples for the pixels in the region specified by (x, y, w, h) in the raster.
double[]getPixels(int x, int y, int w, int h, double[] dArray)
Returns an array containing the samples for the pixels in the region specified by (x, y, w, h) in the raster.
intgetSample(int x, int y, int b)
Returns the sample value for the pixel at (x, y) in the raster.
doublegetSampleDouble(int x, int y, int b)
Returns the sample value for the pixel at (x, y) in the raster.
floatgetSampleFloat(int x, int y, int b)
Returns the sample value for the pixel at (x, y) in the raster.
SampleModelgetSampleModel()
Returns the sample model that accesses the data buffer (to extract pixel data) for this raster.
intgetSampleModelTranslateX()
Returns the x-translation.
intgetSampleModelTranslateY()
Returns the y-translation.
int[]getSamples(int x, int y, int w, int h, int b, int[] iArray)
Returns an array containing the samples from one band for the pixels in the region specified by (x, y, w, h) in the raster.
float[]getSamples(int x, int y, int w, int h, int b, float[] fArray)
Returns an array containing the samples from one band for the pixels in the region specified by (x, y, w, h) in the raster.
double[]getSamples(int x, int y, int w, int h, int b, double[] dArray)
Returns an array containing the samples from one band for the pixels in the region specified by (x, y, w, h) in the raster.
intgetTransferType()
Returns the transfer type for the raster (this is determined by the raster's sample model).
intgetWidth()
Returns the width of the raster.
StringtoString()
Create a String representing the state of this Raster.

Field Detail

dataBuffer

protected DataBuffer dataBuffer
The data buffer used to store the pixel values.

height

protected int height
The height of the raster.

minX

protected int minX
The x-coordinate of the top left corner of the raster.

minY

protected int minY
The y-coordinate of the top left corner of the raster.

numBands

protected int numBands
The number of bands.

numDataElements

protected int numDataElements

parent

protected Raster parent
The raster's parent.

sampleModel

protected SampleModel sampleModel
The sample model used to access the pixel values.

sampleModelTranslateX

protected int sampleModelTranslateX

sampleModelTranslateY

protected int sampleModelTranslateY

width

protected int width
The width of the raster.

Constructor Detail

Raster

protected Raster(SampleModel sampleModel, Point origin)
Creates a new raster.

Parameters: sampleModel the sample model. origin the origin.

Raster

protected Raster(SampleModel sampleModel, DataBuffer dataBuffer, Point origin)
Creates a new raster.

Parameters: sampleModel the sample model. dataBuffer the data buffer. origin the origin.

Raster

protected Raster(SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion, Point sampleModelTranslate, Raster parent)
Creates a new raster.

Parameters: sampleModel the sample model. dataBuffer the data buffer. aRegion the raster's bounds. sampleModelTranslate the translation (null permitted). parent the raster's parent.

Method Detail

createBandedRaster

public static WritableRaster createBandedRaster(int dataType, int w, int h, int bands, Point location)
Creates a new banded raster.

Parameters: dataType the data type. w the width. h the height. bands the number of bands. location

Returns: The new raster.

createBandedRaster

public static WritableRaster createBandedRaster(int dataType, int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location)
Creates a new banded raster.

Parameters: dataType the data type. w the width. h the height. scanlineStride the number of data elements from a sample on one row to the corresponding sample on the next row. bankIndices the index for each bank. bandOffsets the offset for each band. location

Returns: The new raster.

createBandedRaster

public static WritableRaster createBandedRaster(DataBuffer dataBuffer, int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location)
Creates a new banded raster.

Parameters: dataBuffer the data buffer. w the width. h the height. scanlineStride the number of data elements from a sample on one row to the corresponding sample on the next row. bankIndices the index for each bank. bandOffsets the band offsets. location

Returns: The new raster.

createChild

public Raster createChild(int parentX, int parentY, int width, int height, int childMinX, int childMinY, int[] bandList)

createCompatibleWritableRaster

public WritableRaster createCompatibleWritableRaster()
Creates a new writable raster that is compatible with this raster.

Returns: A new writable raster.

createCompatibleWritableRaster

public WritableRaster createCompatibleWritableRaster(int w, int h)
Creates a new writable raster that is compatible with this raster.

Parameters: w the width. h the height.

Returns: A new writable raster.

createCompatibleWritableRaster

public WritableRaster createCompatibleWritableRaster(Rectangle rect)
Creates a new writable raster that is compatible with this raster, with the specified bounds.

Parameters: rect the raster bounds.

Returns: A new writable raster.

createCompatibleWritableRaster

public WritableRaster createCompatibleWritableRaster(int x, int y, int w, int h)
Creates a new writable raster that is compatible with this raster, with the specified bounds.

Parameters: x the x-coordinate of the top-left corner of the raster. y the y-coordinate of the top-left corner of the raster. w the raster width. h the raster height.

Returns: A new writable raster.

createInterleavedRaster

public static WritableRaster createInterleavedRaster(int dataType, int w, int h, int bands, Point location)
Creates an interleaved raster using the specified data type.

Parameters: dataType the data type. w the width. h the height. bands the number of bands. location

Returns: The new raster.

createInterleavedRaster

public static WritableRaster createInterleavedRaster(int dataType, int w, int h, int scanlineStride, int pixelStride, int[] bandOffsets, Point location)
Creates an interleaved raster.

Parameters: dataType the data type. w the width. h the height. scanlineStride the number of data elements from a sample on one row to the corresponding sample on the next row. pixelStride the number of elements from a sample in one pixel to the corresponding sample in the next pixel. bandOffsets the band offsets. location

Returns: The new raster.

createInterleavedRaster

public static WritableRaster createInterleavedRaster(DataBuffer dataBuffer, int w, int h, int scanlineStride, int pixelStride, int[] bandOffsets, Point location)
Creates a new interleaved raster.

Parameters: dataBuffer the data buffer. w the width. h the height. scanlineStride the number of data elements from a sample on one row to the corresponding sample on the next row. pixelStride the number of elements from a sample in one pixel to the corresponding sample in the next pixel. bandOffsets the offset for each band. location

Returns: The new raster.

createPackedRaster

public static WritableRaster createPackedRaster(int dataType, int w, int h, int[] bandMasks, Point location)
Creates a new packed raster.

Parameters: dataType the data type. w the width. h the height. bandMasks the bit mask for each band. location

Returns: The new raster.

createPackedRaster

public static WritableRaster createPackedRaster(int dataType, int w, int h, int bands, int bitsPerBand, Point location)
Creates a new raster.

Parameters: dataType the data type. w the width. h the height. bands the number of bands. bitsPerBand the number of bits per band. location

Returns: The new raster.

createPackedRaster

public static WritableRaster createPackedRaster(DataBuffer dataBuffer, int w, int h, int scanlineStride, int[] bandMasks, Point location)
Creates a new packed raster.

Parameters: dataBuffer the data buffer. w the width. h the height. scanlineStride the number of data elements from a sample on one row to the corresponding sample on the next row. bandMasks the bit mask for each band. location

Returns: The new raster.

createPackedRaster

public static WritableRaster createPackedRaster(DataBuffer dataBuffer, int w, int h, int bitsPerPixel, Point location)
Creates a new packed raster.

Parameters: dataBuffer the data buffer. w the width. h the height. bitsPerPixel the number of bits per pixel. location

Returns: The new raster.

createRaster

public static Raster createRaster(SampleModel sm, DataBuffer db, Point location)
Creates a new raster.

Parameters: sm the sample model. db the data buffer. location

Returns: The new raster.

createTranslatedChild

public Raster createTranslatedChild(int childMinX, int childMinY)

createWritableRaster

public static WritableRaster createWritableRaster(SampleModel sm, Point location)
Creates a new writable raster.

Parameters: sm the sample model. location

Returns: The new writable raster.

createWritableRaster

public static WritableRaster createWritableRaster(SampleModel sm, DataBuffer db, Point location)
Creates a new writable raster.

Parameters: sm the sample model. db the data buffer. location

Returns: The new writable raster.

getBounds

public Rectangle getBounds()
Returns a new rectangle containing the bounds of this raster.

Returns: A new rectangle containing the bounds of this raster.

getDataBuffer

public DataBuffer getDataBuffer()
Returns the data buffer that stores the pixel data for this raster.

Returns: The data buffer.

getDataElements

public Object getDataElements(int x, int y, Object outData)

getDataElements

public Object getDataElements(int x, int y, int w, int h, Object outData)

getHeight

public final int getHeight()
Returns the height of the raster.

Returns: The height of the raster.

getMinX

public final int getMinX()
Returns the x-coordinate of the top left corner of the raster.

Returns: The x-coordinate of the top left corner of the raster.

getMinY

public final int getMinY()
Returns the t-coordinate of the top left corner of the raster.

Returns: The t-coordinate of the top left corner of the raster.

getNumBands

public final int getNumBands()
Returns the number of bands for this raster.

Returns: The number of bands.

getNumDataElements

public final int getNumDataElements()

getParent

public Raster getParent()
Returns the raster's parent.

Returns: The raster's parent.

getPixel

public int[] getPixel(int x, int y, int[] iArray)
Returns an array containing the samples for the pixel at (x, y) in the raster. If iArray is not null, it will be populated with the sample values and returned as the result of this function (this avoids allocating a new array instance).

Parameters: x the x-coordinate of the pixel. y the y-coordinate of the pixel. iArray an array to populate with the sample values and return as the result (if null, a new array will be allocated).

Returns: The pixel sample values.

getPixel

public float[] getPixel(int x, int y, float[] fArray)
Returns an array containing the samples for the pixel at (x, y) in the raster. If fArray is not null, it will be populated with the sample values and returned as the result of this function (this avoids allocating a new array instance).

Parameters: x the x-coordinate of the pixel. y the y-coordinate of the pixel. fArray an array to populate with the sample values and return as the result (if null, a new array will be allocated).

Returns: The pixel sample values.

getPixel

public double[] getPixel(int x, int y, double[] dArray)
Returns an array containing the samples for the pixel at (x, y) in the raster. If dArray is not null, it will be populated with the sample values and returned as the result of this function (this avoids allocating a new array instance).

Parameters: x the x-coordinate of the pixel. y the y-coordinate of the pixel. dArray an array to populate with the sample values and return as the result (if null, a new array will be allocated).

Returns: The pixel sample values.

getPixels

public int[] getPixels(int x, int y, int w, int h, int[] iArray)
Returns an array containing the samples for the pixels in the region specified by (x, y, w, h) in the raster. The array is ordered by pixels (that is, all the samples for the first pixel are grouped together, followed by all the samples for the second pixel, and so on). If iArray is not null, it will be populated with the sample values and returned as the result of this function (this avoids allocating a new array instance).

Parameters: x the x-coordinate of the top-left pixel. y the y-coordinate of the top-left pixel. w the width of the region of pixels. h the height of the region of pixels. iArray an array to populate with the sample values and return as the result (if null, a new array will be allocated).

Returns: The pixel sample values.

getPixels

public float[] getPixels(int x, int y, int w, int h, float[] fArray)
Returns an array containing the samples for the pixels in the region specified by (x, y, w, h) in the raster. The array is ordered by pixels (that is, all the samples for the first pixel are grouped together, followed by all the samples for the second pixel, and so on). If fArray is not null, it will be populated with the sample values and returned as the result of this function (this avoids allocating a new array instance).

Parameters: x the x-coordinate of the top-left pixel. y the y-coordinate of the top-left pixel. w the width of the region of pixels. h the height of the region of pixels. fArray an array to populate with the sample values and return as the result (if null, a new array will be allocated).

Returns: The pixel sample values.

getPixels

public double[] getPixels(int x, int y, int w, int h, double[] dArray)
Returns an array containing the samples for the pixels in the region specified by (x, y, w, h) in the raster. The array is ordered by pixels (that is, all the samples for the first pixel are grouped together, followed by all the samples for the second pixel, and so on). If dArray is not null, it will be populated with the sample values and returned as the result of this function (this avoids allocating a new array instance).

Parameters: x the x-coordinate of the top-left pixel. y the y-coordinate of the top-left pixel. w the width of the region of pixels. h the height of the region of pixels. dArray an array to populate with the sample values and return as the result (if null, a new array will be allocated).

Returns: The pixel sample values.

getSample

public int getSample(int x, int y, int b)
Returns the sample value for the pixel at (x, y) in the raster.

Parameters: x the x-coordinate of the pixel. y the y-coordinate of the pixel. b the band (in the range 0 to getNumBands() - 1).

Returns: The sample value.

getSampleDouble

public double getSampleDouble(int x, int y, int b)
Returns the sample value for the pixel at (x, y) in the raster.

Parameters: x the x-coordinate of the pixel. y the y-coordinate of the pixel. b the band (in the range 0 to getNumBands() - 1).

Returns: The sample value.

See Also: Raster

getSampleFloat

public float getSampleFloat(int x, int y, int b)
Returns the sample value for the pixel at (x, y) in the raster.

Parameters: x the x-coordinate of the pixel. y the y-coordinate of the pixel. b the band (in the range 0 to getNumBands() - 1).

Returns: The sample value.

See Also: Raster

getSampleModel

public SampleModel getSampleModel()
Returns the sample model that accesses the data buffer (to extract pixel data) for this raster.

Returns: The sample model.

getSampleModelTranslateX

public final int getSampleModelTranslateX()
Returns the x-translation.

Returns: The x-translation.

getSampleModelTranslateY

public final int getSampleModelTranslateY()
Returns the y-translation.

Returns: The y-translation.

getSamples

public int[] getSamples(int x, int y, int w, int h, int b, int[] iArray)
Returns an array containing the samples from one band for the pixels in the region specified by (x, y, w, h) in the raster. If iArray is not null, it will be populated with the sample values and returned as the result of this function (this avoids allocating a new array instance).

Parameters: x the x-coordinate of the top-left pixel. y the y-coordinate of the top-left pixel. w the width of the region of pixels. h the height of the region of pixels. b the band (in the range 0 to getNumBands() - 1). iArray an array to populate with the sample values and return as the result (if null, a new array will be allocated).

Returns: The sample values.

getSamples

public float[] getSamples(int x, int y, int w, int h, int b, float[] fArray)
Returns an array containing the samples from one band for the pixels in the region specified by (x, y, w, h) in the raster. If fArray is not null, it will be populated with the sample values and returned as the result of this function (this avoids allocating a new array instance).

Parameters: x the x-coordinate of the top-left pixel. y the y-coordinate of the top-left pixel. w the width of the region of pixels. h the height of the region of pixels. b the band (in the range 0 to getNumBands() - 1). fArray an array to populate with the sample values and return as the result (if null, a new array will be allocated).

Returns: The sample values.

getSamples

public double[] getSamples(int x, int y, int w, int h, int b, double[] dArray)
Returns an array containing the samples from one band for the pixels in the region specified by (x, y, w, h) in the raster. If dArray is not null, it will be populated with the sample values and returned as the result of this function (this avoids allocating a new array instance).

Parameters: x the x-coordinate of the top-left pixel. y the y-coordinate of the top-left pixel. w the width of the region of pixels. h the height of the region of pixels. b the band (in the range 0 to getNumBands() - 1). dArray an array to populate with the sample values and return as the result (if null, a new array will be allocated).

Returns: The sample values.

getTransferType

public final int getTransferType()
Returns the transfer type for the raster (this is determined by the raster's sample model).

Returns: The transfer type.

getWidth

public final int getWidth()
Returns the width of the raster.

Returns: The width of the raster.

toString

public String toString()
Create a String representing the state of this Raster.

Returns: A String representing the stat of this Raster.