Skip to main content

casting problem. Image to BufferedImage

1 reply [Last post]
Joined: 2007-02-26

RenderedImage rendImage = myCreateImage();

try {

file = new File("newimage.jpg");
ImageIO.write(rendImage, "jpg", file);
catch (IOException e) { }

public RenderedImage myCreateImage() {

int width = 384; int height = 288;
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
bufferedImage = (BufferedImage) image;

return bufferedImage; }


I get this exception -> java.lang.ClassCastException: sun.awt.image.ToolkitImage cannot be cast to java.awt.image.BufferedImage
So problem is that I have image and I want to write it on local disc as xxx.jpg file.
In this bold line lies problem.

Message was edited by: luka_k

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Brian Burkhalter

Instead of getImage(url,...) which don't you open an InputStream on the URL,
generate an ImageInputStream from it, and use

On Fri, 9 Mar 2007, wrote:

> [i] //Image image; jpg file that I load from web, image = getImage(url, "xxx.jpg"); [/i]

Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.

To unsubscribe, e-mail:
For additional commands, e-mail: