<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Exiv2: exifprint.cpp</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.9 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> <li> <form action="search.php" method="get"> <table cellspacing="0" cellpadding="0" border="0"> <tr> <td><label> <u>S</u>earch for </label></td> <td><input type="text" name="query" value="" size="20" accesskey="s"/></td> </tr> </table> </form> </li> </ul> </div> </div> <div class="contents"> <h1>exifprint.cpp</h1>Sample program to print Exif data from an image.<p> <div class="fragment"><pre class="fragment"><span class="comment">// ***************************************************************** -*- C++ -*-</span> <span class="comment">// exifprint.cpp, $Rev: 1757 $</span> <span class="comment">// Sample program to print the Exif metadata of an image</span> <span class="preprocessor">#include <exiv2/image.hpp></span> <span class="preprocessor">#include <exiv2/exif.hpp></span> <span class="preprocessor">#include <iostream></span> <span class="preprocessor">#include <iomanip></span> <span class="preprocessor">#include <cassert></span> <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* <span class="keyword">const</span> argv[]) <span class="keyword">try</span> { <span class="keywordflow">if</span> (argc != 2) { std::cout << <span class="stringliteral">"Usage: "</span> << argv[0] << <span class="stringliteral">" file\n"</span>; <span class="keywordflow">return</span> 1; } <a class="code" href="classExiv2_1_1Image.html#89ad3ffe7a4e8a943d267d77843415fb" title="Image auto_ptr type.">Exiv2::Image::AutoPtr</a> image = <a name="a0"></a><a class="code" href="classExiv2_1_1ImageFactory.html#981013bdf0d31ec7f64f0f6339fe323e" title="Create an Image subclass of the appropriate type by reading the specified file. Image...">Exiv2::ImageFactory::open</a>(argv[1]); assert(image.get() != 0); image->readMetadata(); <a name="_a1"></a><a class="code" href="classExiv2_1_1ExifData.html" title="A container for Exif data. This is a top-level class of the Exiv2 library. The container...">Exiv2::ExifData</a> &exifData = image->exifData(); <span class="keywordflow">if</span> (exifData.<a name="a2"></a><a class="code" href="classExiv2_1_1ExifData.html#4993c68fbb50731014c307852875c731" title="Return true if there is no Exif metadata.">empty</a>()) { <a name="a3"></a><a class="code" href="namespaceExiv2.html#5153319711f35fe81cbc13f4b852450c2d79fb07c9ec891f281968dad43c1e25" title="IPTC string type.">std::string</a> error(argv[1]); error += <span class="stringliteral">": No Exif data found in the file"</span>; <span class="keywordflow">throw</span> <a name="_a4"></a><a class="code" href="classExiv2_1_1Error.html" title="Simple error class used for exceptions. An output operator is provided to print errors...">Exiv2::Error</a>(1, error); } <a class="code" href="classExiv2_1_1ExifData.html#2b8ac7a474d6527c0f3f6a0a9cebef77" title="ExifMetadata const iterator type.">Exiv2::ExifData::const_iterator</a> end = exifData.<a name="a5"></a><a class="code" href="classExiv2_1_1ExifData.html#9c15177b03489e3d4bb81e9acc1165fe" title="End of the metadata.">end</a>(); <span class="keywordflow">for</span> (<a class="code" href="classExiv2_1_1ExifData.html#2b8ac7a474d6527c0f3f6a0a9cebef77" title="ExifMetadata const iterator type.">Exiv2::ExifData::const_iterator</a> i = exifData.<a name="a6"></a><a class="code" href="classExiv2_1_1ExifData.html#53bce2980ee060fc2da5fe6751f51db9" title="Begin of the metadata.">begin</a>(); i != end; ++i) { <span class="keyword">const</span> <span class="keywordtype">char</span>* tn = i->typeName(); std::cout << std::setw(44) << std::setfill(<span class="charliteral">' '</span>) << std::left << i->key() << <span class="stringliteral">" "</span> << <span class="stringliteral">"0x"</span> << std::setw(4) << std::setfill(<span class="charliteral">'0'</span>) << std::right << std::hex << i->tag() << <span class="stringliteral">" "</span> << std::setw(9) << std::setfill(<span class="charliteral">' '</span>) << std::left << (tn ? tn : <span class="stringliteral">"Unknown"</span>) << <span class="stringliteral">" "</span> << std::dec << std::setw(3) << std::setfill(<span class="charliteral">' '</span>) << std::right << i->count() << <span class="stringliteral">" "</span> << std::dec << i->value() << <span class="stringliteral">"\n"</span>; } <span class="keywordflow">return</span> 0; } <span class="keywordflow">catch</span> (<a name="_a7"></a><a class="code" href="classExiv2_1_1AnyError.html" title="Error class interface. Allows the definition and use of a hierarchy of error classes...">Exiv2::AnyError</a>& e) { std::cout << <span class="stringliteral">"Caught Exiv2 exception '"</span> << e << <span class="stringliteral">"'\n"</span>; <span class="keywordflow">return</span> -1; } </pre></div> </div> <hr size="1"><address style="text-align: right;"><small>Generated on Thu Jun 25 15:17:11 2009 for Exiv2 by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address> </body> </html>