You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.1 KiB
C++
67 lines
2.1 KiB
C++
21 years ago
|
// ***************************************************************** -*- C++ -*-
|
||
|
/*
|
||
21 years ago
|
Abstract : Sample program showing how to set the Exif comment of an image,
|
||
|
Exif.Photo.UserComment
|
||
21 years ago
|
|
||
|
File: exifcomment.cpp
|
||
21 years ago
|
Version : $Rev$
|
||
21 years ago
|
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
|
||
|
History : 10-May-04, ahu: created
|
||
21 years ago
|
16-Jan-05, ahu: updated using CommentValue and operator trickery
|
||
21 years ago
|
*/
|
||
|
// *****************************************************************************
|
||
|
// included header files
|
||
18 years ago
|
#include <exiv2/image.hpp>
|
||
|
#include <exiv2/exif.hpp>
|
||
21 years ago
|
#include <iostream>
|
||
20 years ago
|
#include <cassert>
|
||
21 years ago
|
|
||
|
// *****************************************************************************
|
||
|
// Main
|
||
|
int main(int argc, char* const argv[])
|
||
|
try {
|
||
|
|
||
|
if (argc != 2) {
|
||
|
std::cout << "Usage: " << argv[0] << " file\n";
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
21 years ago
|
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]);
|
||
20 years ago
|
assert (image.get() != 0);
|
||
|
image->readMetadata();
|
||
21 years ago
|
Exiv2::ExifData &exifData = image->exifData();
|
||
|
|
||
21 years ago
|
/*
|
||
20 years ago
|
Exiv2 uses a CommentValue for Exif user comments. The format of the
|
||
21 years ago
|
comment string includes an optional charset specification at the beginning:
|
||
21 years ago
|
|
||
21 years ago
|
[charset=["]Ascii|Jis|Unicode|Undefined["] ]comment
|
||
21 years ago
|
|
||
21 years ago
|
Undefined is used as a default if the comment doesn't start with a charset
|
||
|
definition.
|
||
21 years ago
|
|
||
21 years ago
|
Following are a few examples of valid comments. The last one is written to
|
||
|
the file.
|
||
21 years ago
|
*/
|
||
20 years ago
|
exifData["Exif.Photo.UserComment"]
|
||
21 years ago
|
= "charset=\"Unicode\" An Unicode Exif comment added with Exiv2";
|
||
20 years ago
|
exifData["Exif.Photo.UserComment"]
|
||
21 years ago
|
= "charset=\"Undefined\" An undefined Exif comment added with Exiv2";
|
||
20 years ago
|
exifData["Exif.Photo.UserComment"]
|
||
21 years ago
|
= "Another undefined Exif comment added with Exiv2";
|
||
20 years ago
|
exifData["Exif.Photo.UserComment"]
|
||
21 years ago
|
= "charset=Ascii An ASCII Exif comment added with Exiv2";
|
||
21 years ago
|
|
||
21 years ago
|
std::cout << "Writing user comment '"
|
||
|
<< exifData["Exif.Photo.UserComment"]
|
||
|
<< "' back to the image\n";
|
||
21 years ago
|
|
||
20 years ago
|
image->writeMetadata();
|
||
21 years ago
|
|
||
20 years ago
|
return 0;
|
||
21 years ago
|
}
|
||
20 years ago
|
catch (Exiv2::AnyError& e) {
|
||
21 years ago
|
std::cout << "Caught Exiv2 exception '" << e << "'\n";
|
||
|
return -1;
|
||
|
}
|