简体   繁体   中英

How to read embed thumbnail from jpeg images?

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?

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.

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.

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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