Java AWT BufferedImage copy image

Description

Java AWT BufferedImage copy image


//package com.demo2s;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage copyImage(BufferedImage image) {
        return copyImage(image, image.getType());
    }/*from  ww  w .  jav a  2  s  .  c o  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;
    }
}



PreviousNext

Related