This method is to copy the input image incase if there raises some error and the actual image is preserved. - Java 2D Graphics

Java examples for 2D Graphics:Image

Description

This method is to copy the input image incase if there raises some error and the actual image is preserved.

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 final int IMAGE_TYPE = BufferedImage.TYPE_3BYTE_BGR;

    /**This method is to copy the input image incase if there raises some error
     * and the actual image is preserved.
     * Clone an image by redrawing it/*  w ww. jav  a 2  s .co  m*/
     * @param img
     * This method is not needed now.
     */
    public static BufferedImage copyImage(BufferedImage img)
            throws OutOfMemoryError {
        int w = img.getWidth();
        int h = img.getHeight();
        BufferedImage image = new BufferedImage(w, h, IMAGE_TYPE);
        image.createGraphics().drawImage(
                img,
                new AffineTransformOp(new AffineTransform(),
                        AffineTransformOp.TYPE_NEAREST_NEIGHBOR), 0, 0);
        return image;
    }
}

Related Tutorials