gpt4 book ai didi

Java/ImageIO 在不读取整个文件的情况下获取图像尺寸?

转载 作者:IT老高 更新时间:2023-10-28 13:53:58 25 4
gpt4 key购买 nike

有没有办法在不读取整个文件的情况下获取图像的尺寸?

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();
}
}
}

感谢 sfussenegger 的建议

关于Java/ImageIO 在不读取整个文件的情况下获取图像尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1559253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com