I have saved generated an image using a byte[] by using

Toolkit.getDefaultToolkit().createImage(image);

where image is a byte[].

The image generated by this is of java.awt.Image instance. Now I want to save this image into my local hard disk as JPEG (the image was decoded as JPEG). How would I do that?.
I am able to draw the image using MediaTracker

Take a look at Java Tutorial - Writing/Saving an Image.

This shows how to save BufferedImage. I dont know how to cast my java.awt.Image to java.awt.image.BufferedImage. If I simply try to use typecasting it gives an error

Exception in thread "main" java.lang.ClassCastException: sun.awt.image.ToolkitImage cannot be cast to java.awt.image.BufferedImage
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.