Question

I've tried using affine transform to scale down a BufferedImage, But I only manage to scale up the image and not make it smaller like I need to.

Here's my scale up code.

public BufferedImage Scale(){
    BufferedImage after = new BufferedImage(before.getWidth(), before.getHeight(), BufferedImage.TYPE_INT_ARGB);
    AffineTransform at = new AffineTransform();
    at.scale(-2.0, -2.0);
    AffineTransformOp scale = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
    after = scale.filter(before, after);
    return after;
}
Was it helpful?

Solution

To scale down, use a scale in the range (0.0, 1.0), instead of negatives.

When you apply a scaling Affine Transform with scale (xScale, yScale), the new dimensions are (imgWidth*xScale, imgHeight*yScale).

OTHER TIPS

If you draw this onto a graphics context, you can specify a new width and height in the drawImage call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top