 |
Exiv2
|
Sample usage of high-level metadata operations.
#include <iostream>
#include <iomanip>
#include <cassert>
int main(int argc, char* const argv[])
try {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " file\n";
return 1;
}
exifData["Exif.Image.Model"] = "Test 1";
exifData["Exif.Image.SamplesPerPixel"] = 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";
rv->read("1/2 1/3");
rv->value_.push_back(std::make_pair(2,3));
rv->value_.push_back(std::make_pair(3,4));
exifData.
add(key, rv.get());
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::kerErrorMessage,
"Key not found");
v = pos->getValue();
if (prv == 0)
throw Exiv2::Error(Exiv2::kerErrorMessage,
"Downcast failed");
rv->value_[2] = std::make_pair(88,77);
pos->setValue(rv.get());
std::cout << "Modified key \"" << key
<< "\", new value \"" << pos->value() << "\"\n";
if (pos == exifData.
end())
throw Exiv2::Error(Exiv2::kerErrorMessage,
"Key not found");
std::cout << "Deleted key \"" << key << "\"\n";
assert(image.get() != 0);
image->setExifData(exifData);
image->writeMetadata();
return 0;
}
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}
std::string toString() const
Return the value as a string.
Definition: exif.cpp:394
iterator findKey(const ExifKey &key)
Find the first Exifdatum with the given key, return an iterator to it.
Definition: exif.cpp:590
void add(const ExifKey &key, const Value *pValue)
Add an Exifdatum from the supplied key and value pair. This method copies (clones) key and value....
Definition: exif.cpp:573
An Exif metadatum, consisting of an ExifKey and a Value and methods to manipulate these.
Definition: exif.hpp:59
Include all Exiv2 header files.
iterator erase(iterator pos)
Delete the Exifdatum at iterator position pos, return the position of the next exifdatum....
Definition: exif.cpp:616
@ asciiString
Exif ASCII type, 8-bit byte.
Definition: types.hpp:132
static AutoPtr create(TypeId typeId)
A (simple) factory to create a Value type.
Definition: value.cpp:100
Error class interface. Allows the definition and use of a hierarchy of error classes which can all be...
Definition: error.hpp:174
iterator end()
End of the metadata.
Definition: exif.hpp:492
static Image::AutoPtr open(const std::string &path, bool useCurl=true)
Create an Image subclass of the appropriate type by reading the specified file. Image type is derived...
Definition: image.cpp:901
const Value & value() const
Return a constant reference to the value.
Definition: exif.cpp:237
friend Exifdatum & setValue(Exifdatum &, const T &)
Set the value of exifDatum to value. If the object already has a value, it is replaced....
Definition: exif.cpp:193
Concrete keys for Exif metadata and access to Exif tag reference data.
Definition: tags.hpp:148
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition: types.hpp:110
std::string key() const
Return the key of the Exifdatum.
Definition: exif.cpp:319
@ date
IPTC date type.
Definition: types.hpp:148
std::auto_ptr< Image > AutoPtr
Image auto_ptr type.
Definition: image.hpp:84
BasicError< char > Error
Error class used for exceptions (std::string based)
Definition: error.hpp:323
std::auto_ptr< ValueType< T > > AutoPtr
Shortcut for a ValueType<T> auto pointer.
Definition: value.hpp:1247
@ string
IPTC string type.
Definition: types.hpp:147
ExifMetadata::iterator iterator
ExifMetadata iterator type.
Definition: exif.hpp:437
Template for a Value of a basic type. This is used for unsigned and signed short, long and rationals.
Definition: value.hpp:1244
std::auto_ptr< Value > AutoPtr
Shortcut for a Value auto pointer.
Definition: value.hpp:63
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition: exif.hpp:434