Issue
As we know, there are some types of BufferedImage like BufferedImage.TYPE_3BYTE_BGR , BufferedImage.TYPE_INT_ARGB , BufferedImage.TYPE_USHORT_565_RGB and so on.
If I only use
BufferedImage image = ImageIO.read(new pngFile(filePath));
What is the type of image.Does it has something to do with the file's format like PNG?
Solution
You can use the getType()
method from BufferedImage
objects:
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
// ...
BufferedImage image = ImageIO.read(new File(filePath));
System.out.println(image.getType());
According to Java Docs:
Returns the image type. If it is not one of the known types, TYPE_CUSTOM is returned.
On OpenJDK 11 running on x86_64 linux platform the above code snippet returns BufferedImage.TYPE_4BYTE_ABGR
(integer value 6).
Edit:
Regarding the last question, you can read this well-elaborated answer. In short:
No, there is no direct relationship between the
BufferedImage
types and file formats.
Answered By - Christian Tapia
Answer Checked By - David Marino (JavaFixing Volunteer)