Read interpreted exif-values from ExifData
I'm a bit confused about the Exiv2-API. I'm trying to read Exif-data and don't understand how to get to interpreted values.
Example: I have a Canon raw-file that I read into an ExifData object and then search for and access specific Exif-tags.
Exiv2::Image::AutoPtr rawImage = Exiv2::ImageFactory::open(argv); rawImage->readMetadata(); Exiv2::ExifData m_RawExif = rawImage->exifData(); Exiv2::ExifData::const_iterator it = m_RawExif.findKey("Exif.CanonSi.ISOSpeed"); printf("%d, %s, %s", it->toLong(), it->toString().c_str(), it->print(&m_RawExif).c_str()); ==> 160, 160, 100
So, I understand that print() interprets the value somehow (correctly) while toLong()/toString() gets me the raw value. But how do I access the interpreted value as an int/long or get a specific component? Do I really have to print all values to a string first and then parse it back myself? I couldn't find an alternative in the API but maybe I missed something...?
Ok, answering myself after reading through some of Exiv2's code.
Seems, like the interpretation of vendor-specific values indeed happens in the print-functions and thus is only available as a string. So, I will have to write some parsing code.
Maybe my use-case is special but that seems like a real limitation of the API. Maybe for future versions it would make sense to extend the tag-field into 'raw' and 'interpreted' values (both typed)? The latter could then still be printed but also accessed via the API.
However, I do realise that that's a major change and I certainly won't be able to contribute, so just food for thought.
But how do I access the interpreted value as an int/long ...
Yes, there's no API for that.
... or get a specific component?
I do not understand this part.
In general, I think your use-case, while perfectly valid, is a bit of a special case: Most of these 'translations' convert some number to a string to make it human-readable, as opposed to another number.
RE: Read interpreted exif-values from ExifData - Added by Mark Allen over 6 years ago
ISOSpeed is also defined in "Exif.CanonCs.ISOSpeed" and "Exif.Photo.ISOSpeed",but your code is " Exiv2::ExifData::const_iterator it = m_RawExif.findKey("Exif.CanonSi.ISOSpeed");", when my program is executed , the result is "value not set",but you get correct result. why?
I think it depends on the individual camera model which tags are written, not all models are completely consistent. For my set of sample-raws, "Exif.CanonSi.ISOSpeed" seemed to be the most common one.
Maybe you happen to have a Canon-model that doesn't write this specific tag?