You can do this using normal ImageIO:
ImageInputStream stream = ImageIO.createImageInputStream(new ByteArrayInputStream(imgData); // assuming imgData is byte[] as in your question
Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
if (!readers.hasNext()) {
// We don't know about this format, give up
}
ImageReader reader = readers.next();
reader.setInput(stream);
// Now query for the properties you like
// Dimensions:
int width = reader.getWidth(0);
int height = reader.getHeight(0);
// File format (you can typically use the first element in the array):
String[] formats = reader.getOriginatingProvider().getFormatNames();
// Color model (note that this will return null for most JPEGs, as Java has no YCbCr color model, but at least this should get you going):
ImageTypeSpecifier type = reader.getRawImageType(0);
ColorModel cm = type.getColorModel();
// ...etc...
For more advanced properties you may want to look into IIOMetadata
, but I find that most of the time I don't need it (and the API is just too much hassle).
You are still limited to the formats listed by ImageIO.getReaderFileSuffixes()
, as Andrew mentioned. You might need to add plugins for specific formats.