有没有一种方法可以获取图像尺寸而无需读取整个文件?
URL url=new URL(<BIG_IMAGE_URL>); BufferedImage img=ImageIO.read(url); System.out.println(img.getWidth()+" "+img.getHeight()); img=null;
try(ImageInputStream in = ImageIO.createImageInputStream(resourceFile)){ final Iterator<ImageReader> readers = ImageIO.getImageReaders(in); if (readers.hasNext()) { ImageReader reader = readers.next(); try { reader.setInput(in); return new Dimension(reader.getWidth(0), reader.getHeight(0)); } finally { reader.dispose(); } } }