public static BufferedImage toBufferedImage(Image img,int type){
  if (img instanceof BufferedImage) {
    return (BufferedImage)img;
  }
  BufferedImage bimage=new BufferedImage(img.getWidth(null),img.getHeight(null),type);
  Graphics2D bGr=bimage.createGraphics();
  bGr.drawImage(img,0,0,null);
  bGr.dispose();
  return bimage;
}

public static BufferedImage toBufferedImage ( Image img , int type ) { if ( img instanceof BufferedImage ) { return ( BufferedImage ) img ; } BufferedImage bimage = new BufferedImage ( img . getWidth ( null ) , img . getHeight ( null ) , type ) ; Graphics2D bGr = bimage . createGraphics ( ) ; bGr . drawImage ( img , 0 , 0 , null ) ; bGr . dispose ( ) ; return bimage ; }
converts a given image into a bufferedimage
