Example usage for java.awt.image AffineTransformOp createCompatibleDestImage

List of usage examples for java.awt.image AffineTransformOp createCompatibleDestImage

Introduction

In this page you can find the example usage for java.awt.image AffineTransformOp createCompatibleDestImage.

Prototype

public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM) 

Source Link

Document

Creates a zeroed destination image with the correct size and number of bands.

Usage

From source file:com.mikenimer.familydam.services.photos.ThumbnailService.java

/**
 * using the metadata orientation transformation information rotate the image.
 * @param image//from   w  ww  . j  av a  2s. c o m
 * @param transform
 * @return
 * @throws Exception
 */
public static BufferedImage transformImage(BufferedImage image, AffineTransform transform) throws Exception {

    AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC);

    BufferedImage destinationImage = op.createCompatibleDestImage(image,
            (image.getType() == BufferedImage.TYPE_BYTE_GRAY) ? image.getColorModel() : null);
    Graphics2D g = destinationImage.createGraphics();
    g.setBackground(Color.WHITE);
    g.clearRect(0, 0, destinationImage.getWidth(), destinationImage.getHeight());
    destinationImage = op.filter(image, destinationImage);
    return destinationImage;
}