Java Image to BufferedImage toBufferedImage(Image img)

Here you can find the source of toBufferedImage(Image img)

Description

to Buffered Image

License

LGPL

Declaration

public static BufferedImage toBufferedImage(Image img) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

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

import javax.swing.ImageIcon;

public class Main {
    public static BufferedImage toBufferedImage(Image img) {

        ImageIcon ii = new ImageIcon(img);
        img = ii.getImage();//from   w ww . ja  v a 2 s  .  co  m

        BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bi.createGraphics();
        g.drawImage(img, 0, 0, null);
        g.dispose();

        return bi;
    }
}

Related

  1. toBufferedImage(Image image)
  2. toBufferedImage(Image image)
  3. toBufferedImage(Image image, int type)
  4. toBufferedImage(Image image, int x, int y)
  5. toBufferedImage(Image img)
  6. toBufferedImage2(Image image)
  7. toGrayBufferedImage(Image image)