简体   繁体   English

如何在不加载图像的情况下获取图像尺寸

[英]How to get dimensions of image without loading the image

I think I'm asking for the impossible, but will ask anyways... 我想我要求不可能,但无论如何都要问......
I have a folder (with several subfolders) which contains a lot of images in JPG and PNG formats. 我有一个文件夹(有几个子文件夹),其中包含许多JPG和PNG格式的图像。 And I need a tool that creates a list of those files including their dimensions. 我需要一个工具来创建这些文件的列表,包括它们的尺寸。 (Width and height.) To do so, I can just load the image into a bitmap and read the Width/Height properties. (宽度和高度。)为此,我可以将图像加载到位图中并读取宽度/高度属性。 This would be okay if the images themselves weren't so huge... 如果图像本身不那么大,那就没关系......
The standard image size is about 8 megapixels but about 10% is between 40 and 100 megapixels. 标准图像尺寸约为800万像素,但约10%是40到100万像素。 (Yes, that's 10,000x10,000 pixels.) This means that I'm dealing with PNG files of 50 to 100 MB each. (是的,这是10,000x10,000像素。)这意味着我正在处理每个50到100 MB的PNG文件。 With a total of 7,500 images this means that my tool is quite busy reading a lot of file data. 总共有7,500张图像,这意味着我的工具正忙于读取大量文件数据。
I need a faster way to read the dimensions of these file types. 我需要一种更快的方式来读取这些文件类型的维度。 Not because of the memory usage, since my system has 32 GB RAM, but because I don't want to wait 45 minutes for the index to be done... (Well, slight exaggeration, but it's not fast.) 不是因为内存使用,因为我的系统有32 GB RAM,但是因为我不想等待45分钟才能完成索引...(好吧,有点夸张,但它并不快。)

You have a complete article and working code in the following link (CodeProject). 您在以下链接(CodeProject)中有完整的文章和工作代码。

http://www.codeproject.com/Articles/35978/Reading-Image-Headers-to-Get-Width-and-Height http://www.codeproject.com/Articles/35978/Reading-Image-Headers-to-Get-Width-and-Height

He is reading the headers information to get the dimensions of the image. 他正在阅读标题信息以获取图像的尺寸。 Performance looks good. 性能看起来不错。

Have a look at jhead here . 看看这里的 jhead。 or exiv2, see here . 或者exiv2,请看这里

It is pretty quick and you could use something like "system()" to run it and parse the output. 它非常快,您可以使用“system()”之类的东西来运行它并解析输出。

Sample output: 样本输出:

File name    : b.jpg
File size    : 643664 bytes
File date    : 2014:02:19 13:07:29
Camera make  : NIKON CORPORATION
Camera model : NIKON D2Xs
Date/Time    : 2007:08:01 11:02:28
Resolution   : 1200 x 797
Flash used   : No
Focal length : 28.0mm  (35mm equivalent: 42mm)
Exposure time: 0.0016 s  (1/640)
Aperture     : f/7.1
ISO equiv.   : 250
Whitebalance : Auto
Metering Mode: center weight
Exposure     : shutter priority (semi-auto)
GPS Latitude : N 52d 13.3690m  0s
GPS Longitude: W  0d 52.7070m  0s
GPS Altitude :  456.00m

Exiv2 handles PNG files as well, and is C-callable as a library so maybe more elegant. Exiv2也处理PNG文件,并且可以作为库进行C调用,因此可能更优雅。

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

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