本文整理匯總了Java中java.awt.image.Raster.getBounds方法的典型用法代碼示例。如果您正苦於以下問題:Java Raster.getBounds方法的具體用法?Java Raster.getBounds怎麽用?Java Raster.getBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.image.Raster
的用法示例。
在下文中一共展示了Raster.getBounds方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: copyData
import java.awt.image.Raster; //導入方法依賴的package包/類
/**
* Copies an arbitrary rectangular region of the RenderedImage
* into a caller-supplied WritableRaster. The region to be
* computed is determined by clipping the bounds of the supplied
* WritableRaster against the bounds of the image. The supplied
* WritableRaster must have a SampleModel that is compatible with
* that of the image.
*
* <p> If the raster argument is null, the entire image will
* be copied into a newly-created WritableRaster with a SampleModel
* that is compatible with that of the image.
*
* @param dest a WritableRaster to hold the returned portion of
* the image.
* @return a reference to the supplied WritableRaster, or to a
* new WritableRaster if the supplied one was null.
*/
public WritableRaster copyData(WritableRaster dest) {
// Get the image bounds.
Rectangle imageBounds = getBounds();
Rectangle bounds;
if (dest == null) {
// Create a WritableRaster for the entire image.
bounds = imageBounds;
Point p = new Point(minX, minY);
SampleModel sm =
sampleModel.createCompatibleSampleModel(width, height);
dest = Raster.createWritableRaster(sm, p);
} else {
bounds = dest.getBounds();
}
// Determine tile limits for the intersection of the prescribed
// bounds with the image bounds.
Rectangle xsect = imageBounds.contains(bounds) ?
bounds : bounds.intersection(imageBounds);
int startX = XToTileX(xsect.x);
int startY = YToTileY(xsect.y);
int endX = XToTileX(xsect.x + xsect.width - 1);
int endY = YToTileY(xsect.y + xsect.height - 1);
// Loop over the tiles in the intersection.
for (int j = startY; j <= endY; j++) {
for (int i = startX; i <= endX; i++) {
// Retrieve the tile.
Raster tile = getTile(i, j);
// Create a child of the tile for the intersection of
// the tile bounds and the bounds of the requested area.
Rectangle tileRect = tile.getBounds();
Rectangle intersectRect =
bounds.intersection(tile.getBounds());
Raster liveRaster = tile.createChild(intersectRect.x,
intersectRect.y,
intersectRect.width,
intersectRect.height,
intersectRect.x,
intersectRect.y,
null);
// Copy the data from the child.
dest.setRect(liveRaster);
}
}
return dest;
}