Maarten
Maarten

Reputation: 663

Is there a way to scale down a BufferedImage

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;
}

Upvotes: 0

Views: 1220

Answers (2)

tbodt
tbodt

Reputation: 16987

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

Upvotes: 0

resueman
resueman

Reputation: 10613

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).

Upvotes: 3

Related Questions