If I have a java.awt.Image object in hand, how can I get a byte array of the image data?
If I had the subclass BufferedImage I could do this:
ByteArrayOutputStream baos = new ByteArrayOutputStream() ;
ImageIO.write( thumbnail , "jpeg" , baos ) ;
baos.flush();
final byte[] bytes = baos.toByteArray() ;
…where ImageIO.write takes an RenderedImage — an interface implemented by BufferedImage but not implemented by its superclass java.awt.Image.
Unfortunately, I do not have a BufferedImage or RenderedImage. After having called getScaledInstance on my original BufferedImage object to get a reduced thumbnail image, I have only a java.awt.Image object in hand. I am trying to get a byte array of the data in that java.awt.Image object.