本文整理汇总了C++中exiv2::exifdata::iterator::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::toString方法的具体用法?C++ iterator::toString怎么用?C++ iterator::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exiv2::exifdata::iterator
的用法示例。
在下文中一共展示了iterator::toString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getExifDateTime
bool getExifDateTime(Exiv2::ExifData &exifData, QDateTime &dateTime) {
bool anyFound = false;
try {
Exiv2::ExifKey key(EXIF_PHOTO_DATETIMEORIGINAL);
Exiv2::ExifData::iterator it = exifData.findKey(key);
if (it != exifData.end()) {
dateTime = QDateTime::fromString(QString::fromLatin1(it->toString().c_str()), Qt::ISODate);
anyFound = dateTime.isValid();
}
if (!anyFound) {
Exiv2::ExifKey imageKey(EXIF_IMAGE_DATETIMEORIGINAL);
Exiv2::ExifData::iterator imageIt = exifData.findKey(imageKey);
if (imageIt != exifData.end()) {
dateTime = QDateTime::fromString(QString::fromLatin1(imageIt->toString().c_str()), Qt::ISODate);
anyFound = dateTime.isValid();
}
}
}
catch (Exiv2::Error &e) {
LOG_WARNING << "Exiv2 error:" << e.what();
anyFound = false;
}
catch (...) {
LOG_WARNING << "Exception";
anyFound = false;
#ifdef QT_DEBUG
throw;
#endif
}
return anyFound;
}
示例2:
bool _getExiv2Value(Exiv2::ExifData& exifData, uint16_t tagID, std::string groupName, std::string & value)
{
Exiv2::ExifData::iterator itr = exifData.findKey(Exiv2::ExifKey(tagID, groupName));
if (itr != exifData.end() && itr->count())
{
value = itr->toString();
return true;
}
else
{
return false;
};
};
示例3: exifData
QDateTime KExiv2::getDigitizationDateTime(bool fallbackToCreationTime) const
{
try
{
// In first, trying to get Date & time from Exif tags.
if (!d->exifMetadata().empty())
{
// Try Exif date time digitized.
Exiv2::ExifData exifData(d->exifMetadata());
Exiv2::ExifKey key("Exif.Photo.DateTimeDigitized");
Exiv2::ExifData::iterator it = exifData.findKey(key);
if (it != exifData.end())
{
QDateTime dateTime = QDateTime::fromString(it->toString().c_str(), Qt::ISODate);
if (dateTime.isValid())
{
kDebug() << "DateTime (Exif digitalized): " << dateTime.toString().toAscii().constData();
return dateTime;
}
}
}
// In second, trying to get Date & time from Iptc tags.
if (!d->iptcMetadata().empty())
{
// Try digitization Iptc date time entries.
Exiv2::IptcData iptcData(d->iptcMetadata());
Exiv2::IptcKey keyDigitizationDate("Iptc.Application2.DigitizationDate");
Exiv2::IptcData::iterator it = iptcData.findKey(keyDigitizationDate);
if (it != iptcData.end())
{
QString IptcDateDigitization(it->toString().c_str());
Exiv2::IptcKey keyDigitizationTime("Iptc.Application2.DigitizationTime");
Exiv2::IptcData::iterator it2 = iptcData.findKey(keyDigitizationTime);
if (it2 != iptcData.end())
{
QString IptcTimeDigitization(it2->toString().c_str());
QDate date = QDate::fromString(IptcDateDigitization, Qt::ISODate);
QTime time = QTime::fromString(IptcTimeDigitization, Qt::ISODate);
QDateTime dateTime = QDateTime(date, time);
if (dateTime.isValid())
{
kDebug() << "Date (IPTC digitalized): " << dateTime.toString().toAscii().constData();
return dateTime;
}
}
}
}
}
catch( Exiv2::Error& e )
{
d->printExiv2ExceptionError("Cannot parse Exif digitization date & time tag using Exiv2 ", e);
}
catch(...)
{
kError() << "Default exception from Exiv2";
}
if (fallbackToCreationTime)
return getImageDateTime();
else
return QDateTime();
}
示例4: main
// *****************************************************************************
// Main
int main()
try {
// Container for all metadata
Exiv2::ExifData exifData;
// *************************************************************************
// Add to the Exif data
// Create a ASCII string value (note the use of create)
Exiv2::Value* v = Exiv2::Value::create(Exiv2::asciiString);
// Set the value to a string
v->read("1999:12:31 23:59:59");
// Add the value together with its key to the Exif data container
Exiv2::ExifKey key("Exif.Photo.DateTimeOriginal");
exifData.add(key, v);
std::cout << "Added key \"" << key << "\", value \"" << *v << "\"\n";
// Delete the memory allocated by Value::create
delete v;
// Now create a more interesting value (without using the create method)
Exiv2::URationalValue* rv = new Exiv2::URationalValue;
// Set two rational components from a string
rv->read("1/2 1/3");
// Add more elements through the extended interface of rational value
rv->value_.push_back(std::make_pair(2,3));
rv->value_.push_back(std::make_pair(3,4));
// Add the key and value pair to the Exif data
key = Exiv2::ExifKey("Exif.Image.PrimaryChromaticities");
exifData.add(key, rv);
std::cout << "Added key \"" << key << "\", value \"" << *rv << "\"\n";
// Delete memory allocated on the heap
delete rv;
// *************************************************************************
// Modify Exif data
// Find the timestamp metadatum by its key
key = Exiv2::ExifKey("Exif.Photo.DateTimeOriginal");
Exiv2::ExifData::iterator pos = exifData.findKey(key);
if (pos == exifData.end()) throw Exiv2::Error("Key not found");
// Modify the value
std::string date = pos->toString();
date.replace(0,4,"2000");
pos->setValue(date);
std::cout << "Modified key \"" << key
<< "\", new value \"" << pos->value() << "\"\n";
// Find the other key
key = Exiv2::ExifKey("Exif.Image.PrimaryChromaticities");
pos = exifData.findKey(key);
if (pos == exifData.end()) throw Exiv2::Error("Key not found");
// Get a pointer to a copy of the value
v = pos->getValue();
// Downcast the Value pointer to its actual type
rv = dynamic_cast<Exiv2::URationalValue*>(v);
if (rv == 0) throw Exiv2::Error("Downcast failed");
// Modify the value directly through the interface of URationalValue
rv->value_[2] = std::make_pair(88,77);
// Copy the modified value back to the metadatum
pos->setValue(rv);
// Delete the memory allocated by getValue
delete v;
std::cout << "Modified key \"" << key
<< "\", new value \"" << pos->value() << "\"\n";
// *************************************************************************
// Delete metadata from the Exif data container
// Delete the metadatum at iterator position pos
key = Exiv2::ExifKey("Exif.Image.PrimaryChromaticities");
pos = exifData.findKey(key);
if (pos == exifData.end()) throw Exiv2::Error("Key not found");
exifData.erase(pos);
std::cout << "Deleted key \"" << key << "\"\n";
// *************************************************************************
// Finally, write the remaining Exif data to an image file
int rc = exifData.write("img_2158.jpg");
if (rc) {
std::string error = Exiv2::ExifData::strError(rc, "img_2158.jpg");
throw Exiv2::Error(error);
}
return 0;
}
catch (Exiv2::Error& e) {
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}
示例5: getDigitizationDateTime
QDateTime MetaEngine::getDigitizationDateTime(bool fallbackToCreationTime) const
{
try
{
// In first, trying to get Date & time from Exif tags.
if (!d->exifMetadata().empty())
{
// Try Exif date time digitized.
Exiv2::ExifData exifData(d->exifMetadata());
Exiv2::ExifKey key("Exif.Photo.DateTimeDigitized");
Exiv2::ExifData::iterator it = exifData.findKey(key);
if (it != exifData.end())
{
QDateTime dateTime = QDateTime::fromString(QString::fromLatin1(it->toString().c_str()), Qt::ISODate);
if (dateTime.isValid())
{
qCDebug(DIGIKAM_METAENGINE_LOG) << "DateTime (Exif digitalized): " << dateTime.toString().toLatin1().constData();
return dateTime;
}
}
}
// In second, we trying XMP
#ifdef _XMP_SUPPORT_
if (!d->xmpMetadata().empty())
{
Exiv2::XmpData xmpData(d->xmpMetadata());
{
Exiv2::XmpKey key("Xmp.exif.DateTimeDigitized");
Exiv2::XmpData::iterator it = xmpData.findKey(key);
if (it != xmpData.end())
{
QDateTime dateTime = QDateTime::fromString(QString::fromLatin1(it->toString().c_str()), Qt::ISODate);
if (dateTime.isValid())
{
qCDebug(DIGIKAM_METAENGINE_LOG) << "DateTime (XMP-Exif digitalized): " << dateTime.toString().toLatin1().constData();
return dateTime;
}
}
}
{
Exiv2::XmpKey key("Xmp.video.DateTimeDigitized");
Exiv2::XmpData::iterator it = xmpData.findKey(key);
if (it != xmpData.end())
{
QDateTime dateTime = QDateTime::fromString(QString::fromLatin1(it->toString().c_str()), Qt::ISODate);
if (dateTime.isValid())
{
qCDebug(DIGIKAM_METAENGINE_LOG) << "DateTime (XMP-Video digitalized): " << dateTime.toString().toLatin1().constData();
return dateTime;
}
}
}
}
#endif // _XMP_SUPPORT_
// In third, trying to get Date & time from Iptc tags.
if (!d->iptcMetadata().empty())
{
// Try digitization Iptc date time entries.
Exiv2::IptcData iptcData(d->iptcMetadata());
Exiv2::IptcKey keyDigitizationDate("Iptc.Application2.DigitizationDate");
Exiv2::IptcData::iterator it = iptcData.findKey(keyDigitizationDate);
if (it != iptcData.end())
{
QString IptcDateDigitization(QString::fromLatin1(it->toString().c_str()));
Exiv2::IptcKey keyDigitizationTime("Iptc.Application2.DigitizationTime");
Exiv2::IptcData::iterator it2 = iptcData.findKey(keyDigitizationTime);
if (it2 != iptcData.end())
{
QString IptcTimeDigitization(QString::fromLatin1(it2->toString().c_str()));
QDate date = QDate::fromString(IptcDateDigitization, Qt::ISODate);
QTime time = QTime::fromString(IptcTimeDigitization, Qt::ISODate);
QDateTime dateTime = QDateTime(date, time);
if (dateTime.isValid())
{
qCDebug(DIGIKAM_METAENGINE_LOG) << "Date (IPTC digitalized): " << dateTime.toString().toLatin1().constData();
return dateTime;
}
}
}
}
//.........这里部分代码省略.........