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

public abstract Class SampleModel

extends Object
Class Inheritance
Known Direct Subclasses
java.awt.image.SinglePixelPackedSampleModel, java.awt.image.ComponentSampleModel, java.awt.image.MultiPixelPackedSampleModel

This abstract class defines an interface for extracting samples of pixels in an image. All image data is expressed as a collection of pixels. Each pixel consists of a number of samples. A sample is a datum for one band of an image and a band consists of all samples of a particular type in an image. For example, a pixel might contain three samples representing its red, green and blue components. There are three bands in the image containing this pixel. One band consists of all the red samples from all pixels in the image. The second band consists of all the green samples and the remaining band consists of all of the blue samples. The pixel can be stored in various formats. For example, all samples from a particular band can be stored contiguously or all samples from a single pixel can be stored contiguously.

Subclasses of SampleModel specify the types of samples they can represent (e.g. unsigned 8-bit byte, signed 16-bit short, etc.) and may specify how the samples are organized in memory. In the Java 2D(tm) API, built-in image processing operators may not operate on all possible sample types, but generally will work for unsigned integral samples of 16 bits or less. Some operators support a wider variety of sample types.

A collection of pixels is represented as a Raster, which consists of a DataBuffer and a SampleModel. The SampleModel allows access to samples in the DataBuffer and may provide low-level information that a programmer can use to directly manipulate samples and pixels in the DataBuffer.

This class is generally a fall back method for dealing with images. More efficient code will cast the SampleModel to the appropriate subclass and extract the information needed to directly manipulate pixels in the DataBuffer.

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

Field Summary

Modifier and TypeField and Description
protected int
dataType

Data type of the DataBuffer storing the pixel data.

protected int
height

Height in pixels of the region of image data that this SampleModel describes.

protected int
numBands

Number of bands of the image data that this SampleModel describes.

protected int
width

Width in pixels of the region of image data that this SampleModel describes.

Constructor Summary

AccessConstructor and Description
public
SampleModel(int
The data type of the DataBuffer storing the pixel data.
dataType
,
int
The width (in pixels) of the region of image data.
w
,
int
The height (in pixels) of the region of image data.
h
,
int
The number of bands of the image data.
numBands
)

Constructs a SampleModel with the specified parameters.

Method Summary

Modifier and TypeMethod and Description
public abstract SampleModel

Returns:

a SampleModel describing the same image data as this SampleModel, but with a different size.
createCompatibleSampleModel
(int
the width of the image data
w
,
int
the height of the image data
h
)

Creates a SampleModel which describes data in this SampleModel's format, but with a different width and height.

public abstract DataBuffer

Returns:

a DataBuffer corresponding to this SampleModel.
createDataBuffer
()

Creates a DataBuffer that corresponds to this SampleModel.

public abstract SampleModel

Returns:

a SampleModel with a subset of bands of this SampleModel.
createSubsetSampleModel
(int[]
the subset of bands of this SampleModel
bands
)

Creates a new SampleModel with a subset of the bands of this SampleModel.

public abstract Object

Returns:

the data elements for the specified pixel.
getDataElements
(int
The X coordinate of the pixel location.
x
,
int
The Y coordinate of the pixel location.
y
,
Object
If non-null, a primitive array in which to return the pixel data.
obj
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

public Object

Returns:

the data elements for the specified region of pixels.
getDataElements
(int
The minimum X coordinate of the pixel rectangle.
x
,
int
The minimum Y coordinate of the pixel rectangle.
y
,
int
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
Object
If non-null, a primitive array in which to return the pixel data.
obj
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

public final int

Returns:

the data type.
getDataType
()

Returns the data type of the DataBuffer storing the pixel data.

public final int

Returns:

the height in pixels of the region of image data that this SampleModel describes.
getHeight
()

Returns the height in pixels.

public final int

Returns:

the number of bands of image data that this SampleModel describes.
getNumBands
()

Returns the total number of bands of image data.

public abstract int

Returns:

the number of data elements.
getNumDataElements
()

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

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[]
If non-null, returns the samples in this array
iArray
,
DataBuffer
The DataBuffer containing the image data
data
)

Returns the samples for a specified pixel in an int array, one sample per array element.

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[]
If non-null, returns the samples in this array.
fArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

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[]
If non-null, returns the samples in this array.
dArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

public int[]

Returns:

the samples for the specified region 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
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
int[]
If non-null, returns the samples in this array.
iArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

public float[]

Returns:

the samples for the specified region 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
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
float[]
If non-null, returns the samples in this array.
fArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

public double[]

Returns:

the samples for the specified region 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
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
double[]
If non-null, returns the samples in this array.
dArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

public abstract int

Returns:

the sample in a specified band for the specified pixel.
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
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

public double

Returns:

the sample in a specified band for the specified pixel.
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
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

public float

Returns:

the sample in a specified band for the specified pixel.
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
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

public int[]

Returns:

the samples for the specified band for the specified region 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
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
int
The band to return.
b
,
int[]
If non-null, returns the samples in this array.
iArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

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 region 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
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
int
The band to return.
b
,
float[]
If non-null, returns the samples in this array.
fArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

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 region 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
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
int
The band to return.
b
,
double[]
If non-null, returns the samples in this array.
dArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

public abstract int[]

Returns:

the size of samples for all bands.
getSampleSize
()

Returns the size in bits of samples for all bands.

public abstract int

Returns:

the size of the samples of the specified band.
getSampleSize
(int
the specified band
band
)

Returns the size in bits of samples for the specified band.

public int

Returns:

the transfer type.
getTransferType
()

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

public final int

Returns:

the width in pixels of the region of image data that this SampleModel describes.
getWidth
()

Returns the width in pixels.

private static native void
public abstract void
setDataElements(int
The X coordinate of the pixel location.
x
,
int
The Y coordinate of the pixel location.
y
,
Object
A primitive array containing pixel data.
obj
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets the data for a single pixel in the specified DataBuffer from a primitive array of type TransferType.

public void
setDataElements(int
The minimum X coordinate of the pixel rectangle.
x
,
int
The minimum Y coordinate of the pixel rectangle.
y
,
int
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
Object
A primitive array containing pixel data.
obj
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets the data for a rectangle of pixels in the specified DataBuffer from a primitive array of type TransferType.

public void
setPixel(int
The X coordinate of the pixel location.
x
,
int
The Y coordinate of the pixel location.
y
,
int[]
The input samples in an int array.
iArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets a pixel in the DataBuffer using an int array of samples for input.

public void
setPixel(int
The X coordinate of the pixel location.
x
,
int
The Y coordinate of the pixel location.
y
,
float[]
The input samples in a float array.
fArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets a pixel in the DataBuffer using a float array of samples for input.

public void
setPixel(int
The X coordinate of the pixel location.
x
,
int
The Y coordinate of the pixel location.
y
,
double[]
The input samples in a double array.
dArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets a pixel in the DataBuffer using a double array of samples for input.

public void
setPixels(int
The X coordinate of the upper left pixel location.
x
,
int
The Y coordinate of the upper left pixel location.
y
,
int
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
int[]
The input samples in an int array.
iArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

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

public void
setPixels(int
The X coordinate of the upper left pixel location.
x
,
int
The Y coordinate of the upper left pixel location.
y
,
int
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
float[]
The input samples in a float array.
fArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets all samples for a rectangle of pixels from a float array containing one sample per array element.

public void
setPixels(int
The X coordinate of the upper left pixel location.
x
,
int
The Y coordinate of the upper left pixel location.
y
,
int
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
double[]
The input samples in a double array.
dArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets all samples for a rectangle of pixels from a double array containing one sample per array element.

public abstract void
setSample(int
The X coordinate of the pixel location.
x
,
int
The Y coordinate of the pixel location.
y
,
int
The band to set.
b
,
int
The input sample as an int.
s
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using an int for input.

public void
setSample(int
The X coordinate of the pixel location.
x
,
int
The Y coordinate of the pixel location.
y
,
int
The band to set.
b
,
float
The input sample as a float.
s
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using a float for input.

public void
setSample(int
The X coordinate of the pixel location.
x
,
int
The Y coordinate of the pixel location.
y
,
int
The band to set.
b
,
double
The input sample as a double.
s
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using a double for input.

public void
setSamples(int
The X coordinate of the upper left pixel location.
x
,
int
The Y coordinate of the upper left pixel location.
y
,
int
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
int
The band to set.
b
,
int[]
The input samples in an int array.
iArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets the samples in the specified band for the specified rectangle of pixels from an int array containing one sample per array element.

public void
setSamples(int
The X coordinate of the upper left pixel location.
x
,
int
The Y coordinate of the upper left pixel location.
y
,
int
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
int
The band to set.
b
,
float[]
The input samples in a float array.
fArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets the samples in the specified band for the specified rectangle of pixels from a float array containing one sample per array element.

public void
setSamples(int
The X coordinate of the upper left pixel location.
x
,
int
The Y coordinate of the upper left pixel location.
y
,
int
The width of the pixel rectangle.
w
,
int
The height of the pixel rectangle.
h
,
int
The band to set.
b
,
double[]
The input samples in a double array.
dArray
,
DataBuffer
The DataBuffer containing the image data.
data
)

Sets the samples in the specified band for the specified rectangle of pixels from a double array containing one sample per array element.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait