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.