public static BufferedImage toBufferedImage(Image im) {
    BufferedImage bi = new BufferedImage
       (im.getWidth(null),im.getHeight(null),BufferedImage.TYPE_INT_RGB);
    Graphics bg = bi.getGraphics();
    bg.drawImage(im, 0, 0, null);
    bg.dispose();
    return bi;
 }