import java.awt.image.*;
import java.awt.*;
import java.awt.geom.*;
import com.sun.image.codec.jpeg.*;
import java.io.*;
import javax.swing.*;

public class ImageTest {
    public static final int WIDTH = 240;
    public static final int HEIGHT = 180;
    public ImageTest() {
        try{
            // get the source image
            Image image = new ImageIcon( "c:\\data\\car.jpg" ).getImage();

            int width = image.getWidth(null);
            int height = image.getHeight(null);

            //create the transformation object and destination image
            AffineTransform transform = new AffineTransform();
            transform.scale( (float)ImageTest.WIDTH/width, (float)ImageTest.HEIGHT/height );
            BufferedImage buffi = new BufferedImage(ImageTest.WIDTH, ImageTest.HEIGHT, BufferedImage.TYPE_INT_RGB);

            //do the transform
            Graphics2D buffig = buffi.createGraphics();
            buffig.drawImage(image, transform, null);

            //write the file out
            OutputStream out = new BufferedOutputStream( new FileOutputStream( "c:\\data\\new.jpg" ) );
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            encoder.encode(buffi);
            out.close();

            System.exit(0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        ImageTest imageTest1 = new ImageTest();
    }
}
1