I know that when I’m using BufferedImage I can call BufferedImage.getColorModel()
but how can I get the same value when I only have an instance of java.awt.Image?
====================================================================================
UPDATED..
OK so . now let me explain extactly what i wanna achieve:
I want to create a method to create some thumbnail of a image.
At first , I convert it to a JPEG file format image and write the result to file,
And then I found if I do that I will lose the original image’s transparency,
So I’m trying to save the target image as PNG file format and mark the BufferedImage as TYPE_BYTE_INDEXED to reduce the size of target file size, but finally i realized if now the original image itself contains lots of color, then I will get a rough quality target image because TYPE_BYTE_INDEXED can’t contains lots color.
SO uh.. now I need to do some research to see if I can get imageType from the Image I got.
if the imageType is originally TYPE_BYTE_INDEXED then I can use TYPE_BYTE_INDEXED also on the target image , otherwise I can use TYPE_BYTE_ARGB or TYPE_BYTE_RGB (it depends on the origin value of the original image ) to make sure that I will a high quality thumbnail and a smaller size image target file.
I don’t know exactly what the method is, but if you can use this method on a
BufferdImageso try to convert yourjava.awt.Imageto aBufferedImage.