Project

General

Profile

Working with EXIF data within a program

Added by Nathan Sullivan almost 12 years ago

I'm still trying to figure out how to work with EXIF within a program. Basically what I'm trying to do is extract a certain field from the file, like just the DateTime, or just the Model of the camera, and save that information to a string. I can follow along pretty well in the exifprint.cpp sample, but this is still a pretty complex thing to follow. I'm fairly certain that it has something to do with tags and keys, like I think the tag for DateTime is 0x0132. But how to turn that information into something useful is where I get lost.

The following piece of code I understand:

    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(  "whatever file" );
    assert(image.get() != 0);
    image->readMetadata();

    Exiv2::ExifData &exifData = image->exifData();
    Exiv2::ExifData::const_iterator end = exifData.end();
    for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) {
    }

I get to the iterator and I think I know what's going on. You're going through the EXIF data one piece at a time, printing out it's values?

I guess what I'm getting at is how would you directly access certain parts of the EXIF data?


Replies (2)

RE: Working with EXIF data within a program - Added by Andreas Huggel almost 12 years ago

That's right. You want to search for a particular metadatum rather than iterate through them. That's done by its key, you don't need the tag number.
Have a look at the addmoddel.cpp sample, in particular the use of findKey() in the section "Modify Exif data" in this example. Once you have an iterator for the metadatum that you want, use Exifdatum::toString to get its value as a string.

Andreas

RE: Working with EXIF data within a program - Added by Nathan Sullivan almost 12 years ago

Ahh. Thank you very much. That was a huge help.

    (1-2/2)