Java/ImageIO getting image dimensions without reading the entire file?

Viewed 34685

Is there a way to get the dimensions of an image without reading the entire file?

URL url=new URL(<BIG_IMAGE_URL>);
BufferedImage img=ImageIO.read(url);
System.out.println(img.getWidth()+" "+img.getHeight());
img=null;
4 Answers

The solution with ImageInputStream and ImageReader is still not so efficient though because they create tmp files. It becomes much slower when image is larger or concurrency is higher, i recommend to use metadata-extractor instead.

Related