All Packages Class Hierarchy This Package Previous Next Index
Class java.awt.image.Raster
java.lang.Object
|
+----java.awt.image.Raster
- public class Raster
- extends Object
This class represents a rectanglular array of pixels and provides
methods for retrieving image data. It contains a DataBuffer object
that holds a buffer of image data in some format, a SampleModel
which describes the format is capable of storing and retrieving
Samples from the DataBuffer, and a Rect that defines the coordinate
space of the raster (upper left corner, width and height).
The Raster's coordinate space is determined by a point and a rectangle.
The Point is the origin of the base Raster (this raster's ancestor
that has no parent.) The rectangle called the bounds determines the
span over which this Raster can process pixel and sample requests.
A point and a rectangle are needed so that sub rasters can use the
same DataBuffer and SampleModel as their parent rasters. The point
marks the origin of the SampleModel in the sub raster's coordinate
space (possibly translated from the parent's coordinate space.) The
rectangle defines the span of the sub raster. For base Rasters, the
upper left corner of the bounds rectangle is equal to the origin.
All constructors are protected. The correct way to create a Raster
is to use one of the static create methods defined in this class.
baseRasterOriginX- The X offset of the base Raster from the global origin.
baseRasterOriginY- The Y offset of the base Raster from the global origin.
dataBuffer- DataBuffer that stores image data.
height- The height of the Raster.
minX- The X offset from the global origin.
minY- The Y offset from the global origin.
numBands- The number of bands in the raster.
numDataElements- The number of data elements per pixel.
parent- If non-null, the parent of this Raster.
sampleModel- SampleModel that describes how pixels are stored in the DataBuffer.
width- The width of the Raster.
Raster(SampleModel, DataBuffer, Point)
- Constructs a Raster with the given SampleModel and DataBuffer.
Raster(SampleModel, DataBuffer, Rectangle, Point, Raster)
- Constructs a Raster with the given SampleModel, DataBuffer, and
parent.
Raster(SampleModel, Point)
- Constructs a Raster with the given SampleModel.
createCompatibleWritableRaster()
- Create a compatible WritableRaster the same size as this Raster with
the same SampleModel and a new initialized DataBuffer.
createCompatibleWritableRaster(int, int)
- Create a compatible WritableRaster with the specified size, a new
SampleModel, and a new initialized DataBuffer.
createComponentRaster(int, int, int, int, int, int[], DataBuffer, Point)
- Creates a Raster based on a ComponentSampleModel with the specified
data type, width, height, scanline stride, pixel stride, band offsets,
and data buffer.
createComponentRaster(int, int, int, int, int, int[], Point)
- Creates a Raster based on a ComponentSampleModel with the specified
data type, width, height, scanline stride, pixel stride, and band
offsets.
createComponentRaster(int, int, int, int, Point)
- Creates a Raster based on a ComponentSampleModel with the specified
data type, width, height, and number of bands.
createPackedRaster(int, int, int, int, DataBuffer, Point)
- Creates a Raster based on a SingleBandPackedSampleModel with the
specified data type, width, height, bits per pixel, and data buffer.
createPackedRaster(int, int, int, int, int, Point)
- Creates a Raster based on a packed SampleModel with the specified
data type, width, height, number of bands, and bits per band.
createPackedRaster(int, int, int, int, int[], DataBuffer, Point)
- Creates a Raster based on a MultiBandPackedSampleModel with the
specified data type, width, height, scanline stride, band masks,
and data buffer.
createPackedRaster(int, int, int, int[], Point)
- Creates a Raster based on a MultiBandPackedSampleModel with the
specified data type, width, height, and band masks.
createRaster(SampleModel, DataBuffer, Point)
- Creates a Raster with the specified SampleModel
createSubRaster(int, int, int, int)
- Returns a Raster which references this Raster's DataBuffer.
createSubRaster(int, int, int, int, int, int, int[])
- Returns a translated SubRaster which references this Raster's
DataBuffer.
createSubRaster(Rectangle)
- Returns a Raster which references this Raster's DataBuffer
createWritableRaster(SampleModel, DataBuffer, Point)
- Creates a WritableRaster with the specified SampleModel
and DataBuffer
createWritableRaster(SampleModel, Point)
- Creates a WritableRaster with the specified SampleModel
getBaseRasterOriginX()
- Returns the X coord of the origin of the base Raster in this Raster's
coordinate system.
getBaseRasterOriginY()
- Returns the Y coord of the origin of the base Raster in this Raster's
coordinate system.
getBaseSubRasterOffsetX()
-
getBaseSubRasterOffsetY()
-
getBounds()
- Returns the bounds Rectangle of this Raster.
getDataBuffer()
- Returns the DataBuffer associated with this Raster.
getHeight()
- Returns the height in pixels of the Raster.
getMinX()
- Returns the minimum X coordinate (in the Raster's coordinate system).
getMinY()
- Returns the minimum Y coordinate (in the Raster's coordinate system).
getNumBands()
- Returns the number of bands in this raster.
getNumDataElements()
- Returns the number of data elements needed to store one pixel.
getParent()
- Returns the parent Raster (if any) of this Raster
getPixel(int, int, double[])
- Returns the samples in an array of double for the specified pixel
getPixel(int, int, float[])
- Returns the samples in an array of Float for the
specified pixel.
getPixel(int, int, int, int, double[])
- Return a double array of pixels representing a region of pixels
getPixel(int, int, int, int, float[])
- Return a float array of pixels representing a region of pixels
getPixel(int, int, int, int, int[])
- Returns a integer array of pixels representing a region of pixels
getPixel(int, int, int[])
- Returns the samples in an array of int for the specified pixel.
getPixelData(int, int, int, int, Object)
- Returns the data elements containing the pixel data for the pixels
in the specified region.
getPixelData(int, int, Object)
- Returns the data elements containing the pixel at x,y in packed
format.
getSample(int, int, int)
- Returns the requested sample in a specified band for a pixel.
getSample(int, int, int, int, int, double[])
- Return an array of ints representing a region of samples
getSample(int, int, int, int, int, float[])
- Returns an array of floats representing a region of samples.
getSample(int, int, int, int, int, int[])
- Returns an array of ints representing a region of samples.
getSampleDouble(int, int, int)
- Returns the requested sample in a specified band for a pixel.
getSampleFloat(int, int, int)
- Returns the requested sample in a specified band for a pixel.
getSampleModel()
- Returns the SampleModel that describes that layout of the image data.
getTransferType()
-
getWidth()
- Returns the width in pixels of the Raster.
sampleModel
protected SampleModel sampleModel
- SampleModel that describes how pixels are stored in the DataBuffer.
dataBuffer
protected DataBuffer dataBuffer
- DataBuffer that stores image data.
width
protected int width
- The width of the Raster.
height
protected int height
- The height of the Raster.
minX
protected int minX
- The X offset from the global origin.
minY
protected int minY
- The Y offset from the global origin.
baseRasterOriginX
protected int baseRasterOriginX
- The X offset of the base Raster from the global origin.
baseRasterOriginY
protected int baseRasterOriginY
- The Y offset of the base Raster from the global origin.
numBands
protected int numBands
- The number of bands in the raster.
numDataElements
protected int numDataElements
- The number of data elements per pixel.
parent
protected Raster parent
- If non-null, the parent of this Raster.
Raster
protected Raster(SampleModel sampleModel,
Point origin)
- Constructs a Raster with the given SampleModel. The Raster's
upper left corner is origin and it is the same size as the
SampleModel. A DataBuffer large enough to describe the
Raster is automatically created.
- Parameters:
- sampleModel - The SampleModel that specifies the layout.
- origin - The Point that specified the origin.
Raster
protected Raster(SampleModel sampleModel,
DataBuffer dataBuffer,
Point origin)
- Constructs a Raster with the given SampleModel and DataBuffer.
The Raster's upper left corner is origin and it is the same size
as the SampleModel. The DataBuffer is not initialized and must
be compatible with SampleModel.
- Parameters:
- sampleModel - The SampleModel that specifies the layout.
- dataBuffer - The DataBufferShort that contains the image data.
- origin - The Point that specifies the origin.
Raster
protected Raster(SampleModel sampleModel,
DataBuffer dataBuffer,
Rectangle aRegion,
Point baseOrigin,
Raster parent)
- Constructs a Raster with the given SampleModel, DataBuffer, and
parent. When translated into the base Raster's coordinate
system, aRegion must be contained by the base Raster. Origin
is the coodinate in the new Raster's coordinate system of the
origin of the base Raster. (The base Raster is the Raster's
ancestor which has no parent.)
Note that this constructor should generally be called by other
constructors or create methods, it should not be used directly.
- Parameters:
- sampleModel - The SampleModel that specifies the layout.
- dataBuffer - The DataBufferShort that contains the image data.
- aRegion - The Rectangle that specifies the image area.
- origin - The Point that specifies the origin.
- parent - The parent (if any) of this raster.
createComponentRaster
public static WritableRaster createComponentRaster(int dataType,
int w,
int h,
int n,
Point location)
- Creates a Raster based on a ComponentSampleModel with the specified
data type, width, height, and number of bands.
createComponentRaster
public static WritableRaster createComponentRaster(int dataType,
int w,
int h,
int scanlineStride,
int pixelStride,
int[] bandOffsets,
Point location)
- Creates a Raster based on a ComponentSampleModel with the specified
data type, width, height, scanline stride, pixel stride, and band
offsets.
createPackedRaster
public static WritableRaster createPackedRaster(int dataType,
int w,
int h,
int[] bandMasks,
Point location)
- Creates a Raster based on a MultiBandPackedSampleModel with the
specified data type, width, height, and band masks.
createPackedRaster
public static WritableRaster createPackedRaster(int dataType,
int w,
int h,
int n,
int bitsPerBand,
Point location)
- Creates a Raster based on a packed SampleModel with the specified
data type, width, height, number of bands, and bits per band.
If the number of bands is one, the SampleModel will be a
SingleBandPackedSampleModel. If the number of bands is more
than one, the SampleModel will be a MultiBandPackedSampleModel,
with each band having bitsPerBand bits. In either case, the
requirements on dataType and bitsPerBand imposed by the corresponding
SampleModel must be met.
createComponentRaster
public static WritableRaster createComponentRaster(int dataType,
int w,
int h,
int scanlineStride,
int pixelStride,
int[] bandOffsets,
DataBuffer dataBuffer,
Point location)
- Creates a Raster based on a ComponentSampleModel with the specified
data type, width, height, scanline stride, pixel stride, band offsets,
and data buffer.
createPackedRaster
public static WritableRaster createPackedRaster(int dataType,
int w,
int h,
int scanlineStride,
int[] bandMasks,
DataBuffer dataBuffer,
Point location)
- Creates a Raster based on a MultiBandPackedSampleModel with the
specified data type, width, height, scanline stride, band masks,
and data buffer.
createPackedRaster
public static WritableRaster createPackedRaster(int dataType,
int w,
int h,
int bitsPerPixel,
DataBuffer dataBuffer,
Point location)
- Creates a Raster based on a SingleBandPackedSampleModel with the
specified data type, width, height, bits per pixel, and data buffer.
createRaster
public static Raster createRaster(SampleModel sm,
DataBuffer dataBuffer,
Point location)
- Creates a Raster with the specified SampleModel
createWritableRaster
public static WritableRaster createWritableRaster(SampleModel sm,
Point location)
- Creates a WritableRaster with the specified SampleModel
createWritableRaster
public static WritableRaster createWritableRaster(SampleModel sm,
DataBuffer db,
Point location)
- Creates a WritableRaster with the specified SampleModel
and DataBuffer
getParent
public Raster getParent()
- Returns the parent Raster (if any) of this Raster
getBaseRasterOriginX
public final int getBaseRasterOriginX()
- Returns the X coord of the origin of the base Raster in this Raster's
coordinate system.
getBaseRasterOriginY
public final int getBaseRasterOriginY()
- Returns the Y coord of the origin of the base Raster in this Raster's
coordinate system.
getBaseSubRasterOffsetX
public final int getBaseSubRasterOffsetX()
getBaseSubRasterOffsetY
public final int getBaseSubRasterOffsetY()
createCompatibleWritableRaster
public WritableRaster createCompatibleWritableRaster()
- Create a compatible WritableRaster the same size as this Raster with
the same SampleModel and a new initialized DataBuffer.
createCompatibleWritableRaster
public WritableRaster createCompatibleWritableRaster(int w,
int h)
- Create a compatible WritableRaster with the specified size, a new
SampleModel, and a new initialized DataBuffer.
createSubRaster
public Raster createSubRaster(Rectangle rect)
- Returns a Raster which references this Raster's DataBuffer
- Parameters:
- rect - is a rectangle in this Raster's coordinate space. An
error is thrown if rect is not fully contained by this Raster.
createSubRaster
public Raster createSubRaster(int x,
int y,
int width,
int height)
- Returns a Raster which references this Raster's DataBuffer.
x,y, width and height form a Rectangle in this Raster's
coordinate space. An error is thrown if this rectangle
is not fully contained by this Raster.
- Parameters:
- x - The X coordinate of the upper left hand corner.
- y - The Y coordinate of the upper left hand corner.
- width - Width of the region starting at (x,y).
- height - Height of the region starting at (x,y).
createSubRaster
public Raster createSubRaster(int x,
int y,
int width,
int height,
int x0,
int y0,
int[] bandList)
- Returns a translated SubRaster which references this Raster's
DataBuffer. x,y, width and height form a Rectangle in this Raster's
coordinate space. The new Raster's coordinate system has an upper
left corner of x0, y0. An error is thrown if rectangle is not
fully contained by this Raster.
- Parameters:
- x - X of the upper left corner in this Raster's coordinates.
- y - Y of the upper left corner in this Raster's coordinates.
- width - Width of the region starting at (x,y).
- height - Height of the region starting at (x,y).
- x0 - X of the upper left corner of returned Raster.
- y0 - Y of the upper left corner of returned Raster.
- bandList - Array of band indices.
getBounds
public Rectangle getBounds()
- Returns the bounds Rectangle of this Raster. This function returns
the same information as getMinX/MinY/Width/Height.
getWidth
public final int getWidth()
- Returns the width in pixels of the Raster.
getHeight
public final int getHeight()
- Returns the height in pixels of the Raster.
getMinX
public final int getMinX()
- Returns the minimum X coordinate (in the Raster's coordinate system).
getMinY
public final int getMinY()
- Returns the minimum Y coordinate (in the Raster's coordinate system).
getNumBands
public final int getNumBands()
- Returns the number of bands in this raster.
getNumDataElements
public final int getNumDataElements()
- Returns the number of data elements needed to store one pixel.
getTransferType
public final int getTransferType()
getPixelData
public Object getPixelData(int x,
int y,
Object obj)
- Returns the data elements containing the pixel at x,y in packed
format.
There will be no explicit bounds checking on the parameters.
An ArrayOutOfBounds exception will be thrown at runtime
if data outside of the array is accessed.
A ClassCastException will be thrown if the input object is non null
and references anything other than an array of transferType.
- Parameters:
- x - The X coordinate of the pixel location.
- y - The Y coordinate of the pixel location.
- outData - 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.
- Returns:
- An object reference to an array of type defined by
getTransferType() with the request pixel data.
getPixelData
public Object getPixelData(int x,
int y,
int w,
int h,
Object obj)
- Returns the data elements containing the pixel data for the pixels
in the specified region.
There will be no explicit bounds checking on the parameters.
An ArrayOutOfBounds exception will be thrown at runtime
if data outside of the array is accessed.
A ClassCastException will be thrown if the input object is non null
and references anything other than an array of transferType.
- Parameters:
- x - The X coordinate of the upper left pixel location.
- y - The Y coordinate of the upper left pixel location.
- width - Width of the pixel rectangle.
- height - Height of the pixel rectangle.
- outData - 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.
- Returns:
- An object reference to an array of type defined by
getTransferType() with the request pixel data.
getPixel
public int[] getPixel(int x,
int y,
int[] iarray)
- Returns the samples in an array of int for the specified pixel.
- Parameters:
- x - The X coordinate of the pixel location.
- y - The Y coordinate of the pixel location.
- iarray - An optionally preallocated int array.
getPixel
public float[] getPixel(int x,
int y,
float[] farray)
- Returns the samples in an array of Float for the
specified pixel.
- Parameters:
- x - The X coordinate of the pixel location.
- y - The Y coordinate of the pixel location.
- farray - An optionally preallocated float array.
getPixel
public double[] getPixel(int x,
int y,
double[] darray)
- Returns the samples in an array of double for the specified pixel
- Parameters:
- x - The X coordinate of the pixel location.
- y - The Y coordinate of the pixel location.
- darray - An optionally preallocated double array.
getPixel
public int[] getPixel(int x,
int y,
int w,
int h,
int[] iarray)
- Returns a integer array of pixels representing a region of pixels
- Parameters:
- x - The X coordinate of the upper left pixel location.
- y - The Y coordinate of the upper left pixel location.
- w - Width of the pixel rectangle.
- h - Height of the pixel rectangle.
- iarray - An optionally pre-allocated int array.
getPixel
public float[] getPixel(int x,
int y,
int w,
int h,
float[] farray)
- Return a float array of pixels representing a region of pixels
- Parameters:
- x - The X coordinate of the upper left pixel location.
- y - The Y coordinate of the upper left pixel location.
- w - Width of the pixel rectangle.
- h - Height of the pixel rectangle.
- farray - An optionally pre-allocated float array.
getPixel
public double[] getPixel(int x,
int y,
int w,
int h,
double[] darray)
- Return a double array of pixels representing a region of pixels
- Parameters:
- x - The X coordinate of the upper left pixel location.
- y - The Y coordinate of the upper left pixel location.
- w - Width of the pixel rectangle.
- h - Height of the pixel rectangle.
- darray - An optionally pre-allocated double array.
getSample
public int getSample(int x,
int y,
int b)
- Returns the requested sample in a specified band for a pixel.
- Parameters:
- x - The X coordinate of the pixel location.
- y - The Y coordinate of the pixel location.
- b - The band to return.
getSampleFloat
public float getSampleFloat(int x,
int y,
int b)
- Returns the requested sample in a specified band for a pixel.
- Parameters:
- x - The X coordinate of the pixel location.
- y - The Y coordinate of the pixel location.
- b - The band to return.
getSampleDouble
public double getSampleDouble(int x,
int y,
int b)
- Returns the requested sample in a specified band for a pixel.
- Parameters:
- x - The X coordinate of the pixel location.
- y - The Y coordinate of the pixel location.
- b - The band to return.
getSample
public int[] getSample(int x,
int y,
int w,
int h,
int b,
int[] iarray)
- Returns an array of ints representing a region of samples.
- Parameters:
- x - The X coordinate of the upper left pixel location.
- y - The Y coordinate of the upper left pixel location.
- w - Width of the pixel rectangle.
- h - Height of the pixel rectangle.
- b - The band to return.
- iarray - An optionally pre-allocated int array.
getSample
public float[] getSample(int x,
int y,
int w,
int h,
int b,
float[] farray)
- Returns an array of floats representing a region of samples.
- Parameters:
- x - The X coordinate of the upper left pixel location.
- y - The Y coordinate of the upper left pixel location.
- w - Width of the pixel rectangle.
- h - Height of the pixel rectangle.
- b - The band to return.
- farray - An optionally pre-allocated float array.
getSample
public double[] getSample(int x,
int y,
int w,
int h,
int b,
double[] darray)
- Return an array of ints representing a region of samples
- Parameters:
- x - The X coordinate of the upper left pixel location.
- y - The Y coordinate of the upper left pixel location.
- w - Width of the pixel rectangle.
- h - Height of the pixel rectangle.
- b - The band to return.
- darray - An optionally pre-allocated double array.
getDataBuffer
public DataBuffer getDataBuffer()
- Returns the DataBuffer associated with this Raster.
getSampleModel
public SampleModel getSampleModel()
- Returns the SampleModel that describes that layout of the image data.
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature