Returns the pixel data for the specified rectangle of pixels in a
primitive array of type TransferType.
For image data supported by the Java 2D API, this
will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT,
or DataBuffer.TYPE_DOUBLE. Data may be returned in a packed format,
thus increasing efficiency for data transfers. Generally, obj
should be passed in as null, so that the Object will be created
automatically and will be of the right primitive data type.
The following code illustrates transferring data for a rectangular
region of pixels from
DataBuffer db1
, whose storage layout is described by
SampleModel sm1
, to DataBuffer db2
, whose
storage layout is described by SampleModel sm2
.
The transfer will generally be more efficient than using
getPixels/setPixels.
SampleModel sm1, sm2;
DataBuffer db1, db2;
sm2.setDataElements(x, y, w, h, sm1.getDataElements(x, y, w,
h, null, db1), db2);
Using getDataElements/setDataElements to transfer between two
DataBuffer/SampleModel pairs is legitimate if the SampleModels have
the same number of bands, corresponding bands have the same number of
bits per sample, and the TransferTypes are the same.
If obj is non-null, it should be a primitive array of type TransferType.
Otherwise, a ClassCastException is thrown. An
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds, or if obj is non-null and is not large enough to hold
the pixel data.
Returns:
the data elements for the specified region of pixels.
Parameters:
- x - The minimum X coordinate of the pixel rectangle.
- y - The minimum Y coordinate of the pixel rectangle.
- w - The width of the pixel rectangle.
- h - The height of the pixel rectangle.
- obj - If non-null, a primitive array in which to return
the pixel data.
- data - The DataBuffer containing the image data.
Throws:
- NullPointerException - if data is null.
- ArrayIndexOutOfBoundsException - if the coordinates are
not in bounds, or if obj is too small to hold the output.
See Also:
SampleModel.getNumDataElements()
,
SampleModel.getTransferType()
,
SampleModel.setDataElements(int, int, int, int, Object, DataBuffer)
,
DataBuffer
,