srecord FitImageInComponentRenderable(BufferedImage srcImage) is Renderable { settable Color backgroundColor = Color.white; public void renderOn(Graphics2D g, int w, int h) { if (backgroundColor != null) { g.setColor(Color.white); g.fillRect(0, 0, w, h); } if (srcImage == null) ret; double scale = scaleToFitInside(srcImage, w, h); int x = (w-iround(srcImage.getWidth()*scale))/2; int y = (h-iround(srcImage.getHeight()*scale))/2; g.translate(x, y); g.scale(scale, scale); g.drawImage(srcImage, 0, 0, null); } }