Blame samples/exifcomment.cpp

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