create BufferedImage from Image - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Create

Description

create BufferedImage from Image

Demo Code


//package com.java2s;
import java.awt.*;
import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage createBufferedImage(Image imageIn,
            int targetColor) {

        BufferedImage bufferedImageOut = new BufferedImage(
                imageIn.getWidth(null), imageIn.getHeight(null),
                targetColor);//from www. jav a  2 s  .com
        Graphics g = bufferedImageOut.getGraphics();
        g.drawImage(imageIn, 0, 0, null);
        g.dispose();
        return bufferedImageOut;
    }
}

Related Tutorials