Converts an image to a BufferedImage. - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Convert

Description

Converts an image to a BufferedImage.

Demo Code


//package com.java2s;
import java.awt.Component;

import java.awt.Image;
import java.awt.image.BufferedImage;

public class Main {
    /**//from  w w w. j  ava 2 s.  c  o  m
     * Converts an image to a BufferedImage.
     * 
     * @param img
     *            Image to be converted.
     * @param c
     *            Component to act as ImageObserver.
     * @return Converted image.
     */
    public static BufferedImage convertImage(Image img, Component c) {
        BufferedImage bimg = new BufferedImage(img.getWidth(c),
                img.getHeight(c), BufferedImage.TYPE_INT_ARGB);
        bimg.getGraphics().drawImage(img, 0, 0, c);
        return bimg;
    }
}

Related Tutorials