Convert Image to BufferedImage in Java

Description

The following code shows how to convert Image to BufferedImage.

Example


  //from   www.ja  va2  s .  co m


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



public class Main {

  /**
   * Creates and returns a buffered version of the specified image.
   *
   * @param image the image to create a buffered image for
   * @return a buffered image based on the specified image
   */
  public static BufferedImage getBufferedImage(Image image) {
    BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
        BufferedImage.TYPE_INT_ARGB);

    Graphics g = bufferedImage.getGraphics();

    g.drawImage(image, 0, 0, null);

    return bufferedImage;
  }




}




















Home »
  Java Tutorial »
    Graphics »




Animation
BufferedImage
Color
Font
Gradient
Graphics Settings
Image
Mouse Draw
Print
Shape
Text
Transform