public void drawScaledImage(BufferedImage im, int x, int y, int w, int h) { float scaleX = w * 1.0f / im.getWidth(); float scaleY = h * 1.0f / im.getHeight(); AffineTransform tx = new AffineTransform(); tx.scale(scaleX, scaleY); BufferedImageOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); drawImage(im, op, x, y); }
// --------------------------------------------------------- private synchronized AffineTransform bufferTransform() { AffineTransform r = new AffineTransform(); for (int i = 0; i < a1.size(); i++) { int s1 = a1.get(i); Object s2 = a2.get(i); Object s3[] = null; if (s2 instanceof Object[]) s3 = (Object[]) s2; if (s1 == setTransform) { r = makeTransform(s2); } if (s1 == shear) r.shear((Double) s3[0], (Double) s3[1]); if (s1 == rotate1) r.rotate((Double) s2); if (s1 == rotate2) r.rotate((Double) s3[0], (Double) s3[1], (Double) s3[2]); if (s1 == scale1) r.scale((Double) s3[0], (Double) s3[1]); if (s1 == translate1) r.translate((Double) s3[0], (Double) s3[1]); if (s1 == translate2) r.translate((Integer) s3[0], (Integer) s3[1]); } return r; }
public void drawScaledImage(BufferedImage im, int x, int y, float scale) { AffineTransform tx = new AffineTransform(); tx.scale(scale, scale); BufferedImageOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); drawImage(im, op, x, y); }