1
// ***************************************************************** -*- C++ -*-
3
Abstract : Sample program showing how to set the Exif comment of an image,
8
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
9
History : 10-May-04, ahu: created
10
16-Jan-05, ahu: updated using CommentValue and operator trickery
12
// *****************************************************************************
13
// included header files
14
#include <exiv2/image.hpp>
15
#include <exiv2/exif.hpp>
19
// *****************************************************************************
21
int main(int argc, char* const argv[])
25
std::cout << "Usage: " << argv[0] << " file\n";
29
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]);
30
assert (image.get() != 0);
31
image->readMetadata();
32
Exiv2::ExifData &exifData = image->exifData();
35
Exiv2 uses a CommentValue for Exif user comments. The format of the
36
comment string includes an optional charset specification at the beginning:
38
[charset=["]Ascii|Jis|Unicode|Undefined["] ]comment
40
Undefined is used as a default if the comment doesn't start with a charset
43
Following are a few examples of valid comments. The last one is written to
46
exifData["Exif.Photo.UserComment"]
47
= "charset=\"Unicode\" An Unicode Exif comment added with Exiv2";
48
exifData["Exif.Photo.UserComment"]
49
= "charset=\"Undefined\" An undefined Exif comment added with Exiv2";
50
exifData["Exif.Photo.UserComment"]
51
= "Another undefined Exif comment added with Exiv2";
52
exifData["Exif.Photo.UserComment"]
53
= "charset=Ascii An ASCII Exif comment added with Exiv2";
55
std::cout << "Writing user comment '"
56
<< exifData["Exif.Photo.UserComment"]
57
<< "' back to the image\n";
59
image->writeMetadata();
63
catch (Exiv2::AnyError& e) {
64
std::cout << "Caught Exiv2 exception '" << e << "'\n";