scale BufferedImage - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Scale

Description

scale BufferedImage

Demo Code


//package com.java2s;

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage scaleBuffImg(BufferedImage buffImg, int w,
            int h) {
        double sx = (double) w / buffImg.getWidth();
        double sy = (double) h / buffImg.getHeight();

        AffineTransform transform = new AffineTransform();
        transform.setToScale(sx, sy);//from w w w . j  a v  a2  s.c o  m
        AffineTransformOp ato = new AffineTransformOp(transform, null);
        BufferedImage newBuffImg = new BufferedImage(w, h,
                BufferedImage.TYPE_3BYTE_BGR);
        ato.filter(buffImg, newBuffImg);
        return newBuffImg;
    }
}

Related Tutorials