C ++ reads EXIF information in JPEG format

Source: Internet
Author: User

You need to read the shooting time of the photo file. The photo is stored in ". jpg" format. Previously, I thought it would be okay to directly read the file creation time. However, the structure of the file information obtained by traversing the file stores the local time of the file, where the file creation time is copied, editing and other operations will change, not the original shooting time of the photo. After searching for EXIF, the encyclopedia said that EXIF is an image file format, and its data storage is exactly the same as JPEG format. In fact, the EXIF format is to insert digital photo information into the JPEG format header. In short, EXIF = JPEG + shooting parameters.

Use the ultraedit and other binary file viewing tools to open ". JPG files can be found that a part of the file header stores a large amount of non-image information, which is actually the EXIF field of the image, including the aperture, shutter, white balance, ISO, focal length, date, and other shooting conditions during shooting, as well as the camera brand, model, color encoding, recording sound during shooting, and the Global Positioning System (GPS) and thumbnails.

Many programs on the Internet read all the shooting parameters and can be used by adding the provided. h and. cpp files. Because you only need to read the shooting time information, you can simply read the information by character.

# Define timeline_begin 13

# Define base 16

# Define max_strlen 100

String get_exiftime (string filename)

{

String exiftime = "";

Fstream fin (filename. c_str (), ifstream: In | ifstream: Binary );

If (fin = NULL)

{

Cerr <"error in open the JPG file" <Endl;

Exit (-1 );

}

Int offset = 0;

Char STR [max_strlen];

Memset (STR, 0, sizeof (STR ));

// Offset = timeline_begin * base + 4 based on the number of files;

Fin. seekg (offset, ifstream: Beg );

Fin. Read (STR, 19 );

Exiftime = STR;

Fin. Close ();

Return exiftime;

}

This blog is reproduced in the Code related to camera photos, which contains the source code of hardware compressed image data to form JPEG files (containing EXIF information.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.