如何从 jpeg 图像中读取嵌入缩略图?
我正在用 C++ 编写缩略图查看器。
我首先利用EXIF信息来检索图像的缩略图,但是EXIF中的缩略图是坏的,有黑条。所以我想获取jpeg的嵌入缩略图,我该怎么做?
另一个问题: jpeg 的嵌入缩略图是否等于 EXIF 缩略图?
I am writing a thumbnail viewer in c++.
I first make use of EXIF information to retrive an image's thumbnail, but the thumbnail in the EXIF is bad, with black bands. So I want to get the jpeg's embedded thumbnail, how can I do this?
Another question:
does jpeg's embeded thumbnail equal to EXIF thumbnial?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果 EXIF 缩略图损坏,您可以从 JPEG 本身生成自己的缩略图,而无需完全解码 JPEG。
查找EPEG的源代码。它是 SourceForge 上 Enlightenment 项目的一部分,也是一年前旧 EFL 的一部分。您仍然可以从一些旧的 SVN 提交或可能存在的源 tarball 中挖掘它。
基本上,EPEG 的作用是从图像中收集 DCT 系数,并对它们执行重新缩放操作。 DCT 系数通常用作 8x8 像素块的基本系数。您可以将其视为一个像素。结果,您得到的缩略图(无需计算)大小恰好是原始图像的 1/8。将其重新缩放,就像将任何图像数据缩放到所需的尺寸一样。
If the EXIF thumbnail is bad, you can generate your own from the JPEG itself, without needing to completely decode the JPEG.
Look for the source code for EPEG. It's part of the Enlightenment project on SourceForge, and was part of the old EFL a year ago. You can still dig it up from some old SVN commits or from a source tarball that might be floating around.
Basically, what EPEG does, is it collects the DCT coefficients from the image, and performs a rescaling operation on them. The DCT coefficient is normally used as the base coefficient for an 8x8 block of pixels. You can treat it as one pixel. As a result, you have a (computationally free) thumbnail exactly 1/8th the size of the original image. Rescale it as you would any image data to the desired dimensions.
在大多数情况下,人们谈论具有缩略图的 JPEG 文件时,他们的意思是该文件是 JPEG-EXIF 并且 EXIF 数据包含缩略图。
不过,JFIF 1.02确实支持缩略图。缩略图可以存储在JFIF APP0标记或官方JFXX APP0扩展标记中;缩略图可以是未压缩的 RGB、JPEG 或调色板。看
http://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#JFIF_segment_format了解详细信息。
In the majority of cases where people talk about JPEG files having thumbnails, they mean the file is JPEG-EXIF and the EXIF data contains a thumbnail image.
However, it is true to say that JFIF 1.02 supports a thumbnail image. The thumbnail may be stored in the JFIF APP0 marker or an official JFXX APP0 extension marker; the thumbnail may be uncompressed RGB, JPEG or palletted. See
http://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#JFIF_segment_format for details.
最快且推荐的方法是图书馆。
例如,www.exiv2.org可以为您提供嵌入缩略图和EXIF信息提取的库。有很多替代方案,但我认为这是一个很好的解决方案。
The fastest and recommended ways are libraries.
For example, www.exiv2.org can provide you with the library for embedded thumbnail and EXIF info extraction. There is a lot of alternatives, but I think this one is a good solution.
在我看来,www.exiv2.org 是一个糟糕的解决方案。其他项目的依赖太多了。例如 Expat 和 zlib。如果您想提出一个可以自己支持的轻量级解决方案,我建议您编写自己的 EXIF 解码器。
www.exiv2.org in my eyes is a bad solution. There are just too many deps to other projects. Expat and zlib for instance. If you want to come up with a lightweight solution that you can support on your own, I would recommend to write your own EXIF decoder.