// from source renderable coordinates to destination
// rendered coordinates.
at.preConcatenate(renderContext.getTransform());
// Create an ROI in destination rendered space.
ROIShape roi = new ROIShape(at.createTransformedShape(rgn));
// Create a TiledImage to contain the masked result.
TiledImage ti = new TiledImage(rendering.getMinX(),
rendering.getMinY(),
rendering.getWidth(),
rendering.getHeight(),
rendering.getTileGridXOffset(),
rendering.getTileGridYOffset(),
rendering.getSampleModel(),
rendering.getColorModel());
// Set the TiledImage data source to the rendering.
ti.set(rendering, roi);
// Create a constant-valued image for the background.
pb = new ParameterBlock();
pb.add((float)ti.getWidth());
pb.add((float)ti.getHeight());
Byte[] bandValues =
new Byte[ti.getSampleModel().getNumBands()];
for(int b = 0; b < bandValues.length; b++) {
bandValues[b] = new Byte((byte)255);
}
pb.add(bandValues);
ImageLayout il = new ImageLayout();
il.setSampleModel(ti.getSampleModel());
RenderingHints rh = new RenderingHints(JAI.KEY_IMAGE_LAYOUT,
il);
PlanarImage constImage = JAI.create("constant", pb, rh);
// Compute a complement ROI.
ROI complementROI =
(new ROIShape(ti.getBounds())).subtract(roi);;
// Fill the background.
int maxTileY = ti.getMaxTileY();
int maxTileX = ti.getMaxTileX();
for(int j = ti.getMinTileY(); j <= maxTileY; j++) {
for(int i = ti.getMinTileX(); i <= maxTileX; i++) {
if(!roi.intersects(ti.getTileRect(i, j))) {
ti.setData(constImage.getTile(i, j),
complementROI);
}
}
}