copy BufferedImage via Graphics2D - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Paint

Description

copy BufferedImage via Graphics2D

Demo Code


//package com.java2s;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage copyImage(BufferedImage image) {
        return copyImage(image, image.getType());
    }/*ww w  .  ja va  2 s.  co m*/

    public static BufferedImage copyImage(BufferedImage image, int type) {
        BufferedImage copy = new BufferedImage(image.getWidth(),
                image.getHeight(), type);
        Graphics2D graphics2D = copy.createGraphics();
        graphics2D.drawImage(image, 0, 0, null);
        graphics2D.dispose();
        return copy;
    }
}

Related Tutorials