The task: I have some images, I scale them down, and join them to one image. But I have a little problem with the implementation:

The concrete problem: I want to resize/scale a BufferedImage. The getScaledInstance method returns an Image object, but I can't cast it to BufferedImage:

Exception in thread "main" java.lang.ClassCastException: sun.awt.image.ToolkitImage cannot be cast to java.awt.image.BufferedImage

(I don't know why is it a ToolkitImage instead of an Image...)

I found a solution:

Image tmp = bi.getScaledInstance(SMALL_SIZE, SMALL_SIZE, BufferedImage.SCALE_FAST);
BufferedImage buffered = new BufferedImage(SMALL_SIZE,SMALL_SIZE,BufferedImage.TYPE_INT_RGB);
buffered.getGraphics().drawImage(tmp, 0, 0, null);

But it's slow, and I think there should be a better way to do it.

I need the BufferedImage, because I have to get the pixels to join the small images.

Is there a better (nicer/faster) way to do it?

EDIT: If I cast the Image first to ToolkitImage, it has a getBufferedImage() method. But it always returns null. Do you know why?

Edit
Report