import com.imageresize4j.jai.ImprovedScaleDescriptor;
import com.imageresize4j.jai.ImprovedScaleInterpolation;

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageOutputStream;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.media.jai.RenderedOp;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;

/**
 * ImageResize4J JAI "Sharp Light 5" Image Resize Example
 */
public class IR4JJAIImageResizeExample {

    public static void main(String[] args) {
        try {
            PlanarImage image = JAI.create("fileload", args[0]);
            Integer destWidth = new Integer(args[1]);
            Integer destHeight = null;
            if (args.length == 3)
                destHeight = new Integer(args[2]);
            RenderedOp renderedOp = ImprovedScaleDescriptor.createResize(image, destWidth, destHeight,
                    ImprovedScaleInterpolation.SHARP_LIGHT_5, null);

            writeJPEG(renderedOp.getAsBufferedImage()"D:\\output.jpg");
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void writeJPEG(BufferedImage input, String namethrows IOException {
        Iterator iter =
                ImageIO.getImageWritersByFormatName("JPG");
        if (iter.hasNext()) {
            ImageWriter writer = (ImageWriteriter.next();
            ImageWriteParam iwp =
                    writer.getDefaultWriteParam();
            iwp.setCompressionMode(
                    ImageWriteParam.MODE_EXPLICIT);
            iwp.setCompressionQuality(0.95f);
            File outFile = new File(name);
            FileImageOutputStream output =
                    new FileImageOutputStream(outFile);
            writer.setOutput(output);
            IIOImage image =
                    new IIOImage(input, null, null);
            writer.write(null, image, iwp);
            output.close();
        }
    }
}
Java2html