Skip to content
Advertisement

Java : read an image inside a binary file (or maybe more generally, from a stream)

I am making a java program that reads a binary file, which contains multiple images (in PNG format), and some binary data.

How can i load the images (specifically, as java.awt.Image‘s) ? So far the only way i have found to load an image is via functions that just take a file. How can i do it from, say, an InputStream ?

Advertisement

Answer

The ImageIO#read(InputStream) method does return a java.awt.image.BufferedImage (which extends from java.awt.Image).

https://docs.oracle.com/javase/8/docs/api/javax/imageio/ImageIO.html#read-java.io.InputStream-

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement