简体   繁体   English

无需从 java 中的 web 下载即可获取图像大小

[英]get image size without downloading them from web in java

I want to get height, width, and size in bytes without downloading them completely.我想在不完全下载的情况下以字节为单位获取高度、宽度和大小。 I need to do that in java.我需要在 java 中这样做。 Is there any way to get images metadata without download those images completely?有没有办法在不完全下载这些图像的情况下获取图像元数据?

All those informations are kept in the image itself.所有这些信息都保存在图像本身中。 (From my knowledge) You can only do what you're asking if you have an API that you can consume which will tell you those informations beforehand but you can't get that from an URL at the end of which you find the image byte array. (据我所知)你只能做你要问的事情,如果你有一个可以使用的 API,它会事先告诉你这些信息,但你不能从 URL 中得到这些信息,最后你可以找到图像字节大批。

If you could selectively download only the exif data, you'd be fine, but depending on the image format the location of it may be unknown before actually downloading the entire image to parse it.如果您可以选择性地仅下载 exif 数据,那会很好,但根据图像格式,在实际下载整个图像以解析它之前,它的位置可能是未知的。 What you can do is make a HTTP HEAD request to only get the Content-Length and Content-Type headers though, and make some qualified guesses about the image size.您可以做的是发出 HTTP HEAD 请求以仅获取 Content-Length 和 Content-Type 标头,并对图像大小进行一些合格的猜测。 This gives no information about aspect, width or height of course, only the number of bytes.当然,这没有提供有关方面、宽度或高度的信息,只提供字节数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM