protected void addImage(Graphics2D graphics, ImageResult imageResult, MapViewport viewport) throws IOException {
Rectangle screenArea = viewport.getScreenArea();
ReferencedEnvelope worldBounds = viewport.getBounds();
// convert map bounds to application bounds
double rasterScale = screenArea.getWidth() / worldBounds.getWidth();
Envelope applicationBounds = new Envelope(worldBounds.getMinX() * rasterScale, worldBounds.getMaxX()
* rasterScale, -worldBounds.getMinY() * rasterScale, -worldBounds.getMaxY() * rasterScale);
Bbox imageBounds = imageResult.getRasterImage().getBounds();
// find transform between image bounds and application bounds
double tx = (imageBounds.getX() - applicationBounds.getMinX());
double ty = (imageBounds.getY() - applicationBounds.getMinY());
BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageResult.getImage()));
double scaleX = imageBounds.getWidth() / image.getWidth();
double scaleY = imageBounds.getHeight() / image.getHeight();
AffineTransform transform = new AffineTransform();
transform.translate(tx, ty);