BufferedImage bimage = new BufferedImage(w, h,
BufferedImage.TYPE_INT_RGB);
Graphics g = bimage.getGraphics();
try {
if (im instanceof ToolkitImage) {
ImageRepresentation ir = ((ToolkitImage)im).getImageRep();
ir.reconstruct(ImageObserver.ALLBITS);
}
g.drawImage(im, 0, 0, w, h, null);
} finally {
g.dispose();
}