Sample usage of high-level metadata operations.
#include <exiv2/exiv2.hpp>
#include <iostream>
int main(int argc, char* const argv[]) {
try {
#ifdef EXV_ENABLE_BMFF
Exiv2::enableBMFF();
#endif
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " file\n";
return EXIT_FAILURE;
}
std::string file(argv[1]);
exifData["Exif.Image.Model"] = "Test 1";
exifData["Exif.Image.SamplesPerPixel"] = static_cast<uint16_t>(162);
exifData["Exif.Image.XResolution"] = -2;
std::cout << "Added a few tags the quick way.\n";
v->read("1999:12:31 23:59:59");
exifData.
add(key, v.get());
std::cout << "Added key \"" << key << "\", value \"" << *v << "\"\n";
std::cout << "Added key \"" << key << "\", value \"" << rv << "\"\n";
date.replace(0, 4, "2000");
std::cout <<
"Modified key \"" << tag.
key() <<
"\", new value \"" << tag.
value() <<
"\"\n";
if (pos == exifData.
end())
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,
"Key not found");
v = pos->getValue();
if (!prv)
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,
"Downcast failed");
rv.value_.at(2) = {88, 77};
pos->setValue(&rv);
std::cout << "Modified key \"" << key << "\", new value \"" << pos->value() << "\"\n";
if (pos == exifData.
end())
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,
"Key not found");
std::cout << "Deleted key \"" << key << "\"\n";
image->setExifData(exifData);
image->writeMetadata();
return EXIT_SUCCESS;
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return EXIT_FAILURE;
}
}