image To Buffered Image - Java 2D Graphics

Java examples for 2D Graphics:Image Convert

Description

image To Buffered Image

Demo Code


//package com.java2s;

import java.awt.Graphics2D;
import java.awt.Image;

import java.awt.image.BufferedImage;

public class Main {
    private static BufferedImage imageToBufferedImage(Image image) {

        BufferedImage bufferedImage = new BufferedImage(
                image.getWidth(null), image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = bufferedImage.createGraphics();
        g2.drawImage(image, 0, 0, null);
        g2.dispose();/* w  w w.  ja v a  2 s. c  o  m*/

        return bufferedImage;

    }
}

Related Tutorials