/** {@inheritDoc} */
public void handleImage(RenderingContext context, Image image, Rectangle pos)
throws IOException {
Java2DRenderingContext java2dContext = (Java2DRenderingContext)context;
ImageInfo info = image.getInfo();
ImageRendered imageRend = (ImageRendered)image;
Graphics2D g2d = java2dContext.getGraphics2D();
AffineTransform at = new AffineTransform();
at.translate(pos.x, pos.y);
//scaling based on layout instructions
double sx = pos.getWidth() / (double)info.getSize().getWidthMpt();
double sy = pos.getHeight() / (double)info.getSize().getHeightMpt();
//scaling because of image resolution
//float sourceResolution = java2dContext.getUserAgent().getSourceResolution();
//source resolution seems to be a bad idea, not sure why
float sourceResolution = GraphicsConstants.DEFAULT_DPI;
sourceResolution *= 1000; //we're working in the millipoint area
sx *= sourceResolution / info.getSize().getDpiHorizontal();
sy *= sourceResolution / info.getSize().getDpiVertical();
at.scale(sx, sy);
RenderedImage rend = imageRend.getRenderedImage();
if (imageRend.getTransparentColor() != null && !rend.getColorModel().hasAlpha()) {
int transCol = imageRend.getTransparentColor().getRGB();
BufferedImage bufImage = makeTransparentImage(rend);
WritableRaster alphaRaster = bufImage.getAlphaRaster();
//TODO Masked images: Does anyone know a more efficient method to do this?
final int[] transparent = new int[] {0x00};
for (int y = 0, maxy = bufImage.getHeight(); y < maxy; y++) {