本文整理汇总了C++中exiv2::ExifData::findKey方法的典型用法代码示例。如果您正苦于以下问题:C++ ExifData::findKey方法的具体用法?C++ ExifData::findKey怎么用?C++ ExifData::findKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exiv2::ExifData
的用法示例。
在下文中一共展示了ExifData::findKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: orientationToAngle
void DB::FileInfo::parseEXIV2( const DB::FileName& fileName )
{
Exiv2::ExifData map = Exif::Info::instance()->metadata( fileName ).exif;
// Date
m_date = fetchEXIV2Date( map, "Exif.Photo.DateTimeOriginal" );
if ( !m_date.isValid() ) {
m_date = fetchEXIV2Date( map, "Exif.Photo.DateTimeDigitized" );
if ( !m_date.isValid() )
m_date = fetchEXIV2Date( map, "Exif.Image.DateTime" );
}
// Angle
if ( map.findKey( Exiv2::ExifKey( "Exif.Image.Orientation" ) ) != map.end() ) {
const Exiv2::Exifdatum& datum = map["Exif.Image.Orientation"];
int orientation = 0;
if (datum.count() > 0)
orientation = datum.toLong();
m_angle = orientationToAngle( orientation );
}
// Description
if( map.findKey( Exiv2::ExifKey( "Exif.Image.ImageDescription" ) ) != map.end() ) {
const Exiv2::Exifdatum& datum = map["Exif.Image.ImageDescription"];
m_description = QString::fromLocal8Bit( datum.toString().c_str() );
}
}
示例2: 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;
}
示例3: HasExifKey
/** \fn ImageUtils::HasExifKey(Exiv2::ExifData, const QString &)
* \brief Checks if the exif data of the file contains the given key
* \param exifData The entire exif data
* \param exifTag The key that shall be checked
* \return True if the exif key exists, otherwise false
*/
bool ImageUtils::HasExifKey(Exiv2::ExifData exifData,
const QString &exifTag)
{
Exiv2::ExifKey key(exifTag.toLocal8Bit().constData());
Exiv2::ExifData::iterator it = exifData.findKey(key);
// If the iterator has is the end of the
// list then the key has not been found
return !(it == exifData.end());
}
示例4:
bool _getExiv2Value(Exiv2::ExifData& exifData, std::string keyName, float & value)
{
Exiv2::ExifData::iterator itr = exifData.findKey(Exiv2::ExifKey(keyName));
if (itr != exifData.end() && itr->count())
{
value = itr->toFloat();
return true;
}
else
{
return false;
};
};
示例5: clearGPSFields
void clearGPSFields(Exiv2::ExifData &exifData) {
std::list<std::string> fields = {"Exif.GPSInfo.GPSLatitude",
"Exif.GPSInfo.GPSLongitude",
"Exif.GPSInfo.GPSMapDatum",
"Exif.GPSInfo.GPSLatitudeRef",
"Exif.GPSInfo.GPSLongitudeRef",
"Exif.GPSInfo.GPSLatitude",
"Exif.GPSInfo.GPSLongitude",
"Exif.GPSInfo.GPSAltitude",
"Exif.GPSInfo.GPSAltitudeRef",
"Exif.GPSInfo.GPSTimeStamp",
"Exif.GPSInfo.GPSDateStamp",};
for (auto fname : fields) {
auto key = Exiv2::ExifKey(fname.c_str());
auto iter = exifData.findKey(key);
while (iter != exifData.end()) {
exifData.erase(iter);
iter = exifData.findKey(key);
}
}
}
示例6: fromString
QDateTime FileInfo::fetchEXIV2Date( Exiv2::ExifData& map, const char* key )
{
try
{
if ( map.findKey( Exiv2::ExifKey( key ) ) != map.end() ) {
const Exiv2::Exifdatum& datum = map[key ];
return QDateTime::fromString( QString::fromLatin1(datum.toString().c_str()), Qt::ISODate );
}
}
catch (...)
{
}
return QDateTime();
}
示例7: readExifItem
QString ExifReaderWriter::readExifItem( Exiv2::ExifData &exifData, std::string keyStr)
{
try{
Exiv2::ExifKey key(keyStr);
Exiv2::ExifData::iterator pos = exifData.findKey(key);
if(pos != exifData.end())
{
return exifData[keyStr].toString().data();
}
}
catch (Exiv2::Error& e) {
;//std::cerr << "Caught Exiv2 exception '" << e.what() << "'\n";
}
return "";
}
示例8: getExifCommentValue
QString getExifCommentValue(Exiv2::ExifData &exifData, const char *propertyName) {
QString result;
Exiv2::ExifKey key(propertyName);
Exiv2::ExifData::iterator it = exifData.findKey(key);
if (it != exifData.end()) {
const Exiv2::Exifdatum& exifDatum = *it;
std::string comment;
std::string charset;
comment = exifDatum.toString();
// libexiv2 will prepend "charset=\"SomeCharset\" " if charset is specified
// Before conversion to QString, we must know the charset, so we stay with std::string for a while
if (comment.length() > 8 && comment.substr(0, 8) == "charset=") {
// the prepended charset specification is followed by a blank
std::string::size_type pos = comment.find_first_of(' ');
if (pos != std::string::npos) {
// extract string between the = and the blank
charset = comment.substr(8, pos-8);
// get the rest of the string after the charset specification
comment = comment.substr(pos+1);
}
}
if (charset == "\"Unicode\"") {
result = QString::fromUtf8(comment.data());
}
else if (charset == "\"Jis\"") {
QTextCodec* const codec = QTextCodec::codecForName("JIS7");
result = codec->toUnicode(comment.c_str());
}
else if (charset == "\"Ascii\"") {
result = QString::fromLatin1(comment.c_str());
} else {
result = Helpers::detectEncodingAndDecode(comment);
}
}
return result;
}
示例9: writeData
void ExifReaderWriter::writeData(Exiv2::ExifData &exifData, std::string keyStr, QString str)
{
try{
Exiv2::ExifKey key(keyStr);
Exiv2::ExifData::iterator pos = exifData.findKey(key);
if(pos != exifData.end()){
exifData[keyStr].setValue(str.toStdString());
}
else //vytvorim novou polozku
{
exifData[keyStr].setValue(str.toStdString());
}
}
catch (Exiv2::Error& e) {
;//std::cerr << "Caught Exiv2 exception '" << e.what() << "'\n";
}
}
示例10: tag_location
bool tag_location( const std::string &filename, const location &loc)
{
bool result = false;
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open( filename);
if (!image.get()) throw std::runtime_error( "could not open image file " + filename + " for metadata tags\n");
image->readMetadata();
Exiv2::ExifData data = image->exifData();
if (data.findKey( Exiv2::ExifKey("Exif.GPSInfo.GPSLatitude")) == data.end())
{
add_exif_coordinate( data, "Exif.GPSInfo.GPSLatitude", std::abs( loc.latitude));
add_exif_coordinate( data, "Exif.GPSInfo.GPSLongitude", std::abs( loc.longitude));
data["Exif.GPSInfo.GPSLatitudeRef"] = loc.latitude < 0 ? "S":"N";
data["Exif.GPSInfo.GPSLongitudeRef"] = loc.longitude < 0 ? "W":"E";
Exiv2::byte version[] = { 2, 0, 0, 0};
data["Exif.GPSInfo.GPSVersionID"].getValue()->read( version, 4, Exiv2::invalidByteOrder);
image->setExifData( data);
image->writeMetadata();
result = true;
}
return result;
}
示例11: WriteExif
bool ptImageHelper::WriteExif(const QString &AFileName,
const std::vector<uint8_t> &AExifBuffer,
Exiv2::IptcData &AIptcData,
Exiv2::XmpData &AXmpData) {
try {
#if EXIV2_TEST_VERSION(0,17,91) /* Exiv2 0.18-pre1 */
Exiv2::ExifData hInExifData;
Exiv2::ExifParser::decode(hInExifData,
AExifBuffer.data() + CExifHeader.size(),
AExifBuffer.size() - CExifHeader.size());
// Reset orientation
Exiv2::ExifData::iterator pos = hInExifData.begin();
if ((pos = hInExifData.findKey(Exiv2::ExifKey("Exif.Image.Orientation"))) != hInExifData.end()) {
pos->setValue("1"); // Normal orientation
}
// Adapted from UFRaw, necessary for Tiff files
QStringList ExifKeys;
ExifKeys << "Exif.Image.ImageWidth"
<< "Exif.Image.ImageLength"
<< "Exif.Image.BitsPerSample"
<< "Exif.Image.Compression"
<< "Exif.Image.PhotometricInterpretation"
<< "Exif.Image.FillOrder"
<< "Exif.Image.SamplesPerPixel"
<< "Exif.Image.StripOffsets"
<< "Exif.Image.RowsPerStrip"
<< "Exif.Image.StripByteCounts"
<< "Exif.Image.XResolution"
<< "Exif.Image.YResolution"
<< "Exif.Image.PlanarConfiguration"
<< "Exif.Image.ResolutionUnit";
for (short i = 0; i < ExifKeys.count(); i++) {
if ((pos = hInExifData.findKey(Exiv2::ExifKey(ExifKeys.at(i).toLocal8Bit().data()))) != hInExifData.end())
hInExifData.erase(pos);
}
if (Settings->GetInt("EraseExifThumbnail")) {
Exiv2::ExifThumb Thumb(hInExifData);
Thumb.erase();
}
QStringList JpegExtensions;
JpegExtensions << "jpg" << "JPG" << "Jpg" << "jpeg" << "Jpeg" << "JPEG";
bool deleteDNGdata = false;
for (short i = 0; i < JpegExtensions.count(); i++) {
if (!AFileName.endsWith(JpegExtensions.at(i))) deleteDNGdata = true;
}
Exiv2::Image::AutoPtr Exiv2Image = Exiv2::ImageFactory::open(AFileName.toLocal8Bit().data());
Exiv2Image->readMetadata();
Exiv2::ExifData outExifData = Exiv2Image->exifData();
for (auto hPos = hInExifData.begin(); hPos != hInExifData.end(); hPos++) {
if (!deleteDNGdata || (*hPos).key() != "Exif.Image.DNGPrivateData") {
outExifData.add(*hPos);
}
}
// IPTC data
QStringList Tags = Settings->GetStringList("TagsList");
QStringList DigikamTags = Settings->GetStringList("DigikamTagsList");
Exiv2::StringValue StringValue;
for (int i = 0; i < Tags.size(); i++) {
StringValue.read(Tags.at(i).toStdString());
AIptcData.add(Exiv2::IptcKey("Iptc.Application2.Keywords"), &StringValue);
}
// XMP data
for (int i = 0; i < Tags.size(); i++) {
AXmpData["Xmp.dc.subject"] = Tags.at(i).toStdString();
}
for (int i = 0; i < DigikamTags.size(); i++) {
AXmpData["Xmp.digiKam.TagsList"] = DigikamTags.at(i).toStdString();
}
// Image rating
outExifData["Exif.Image.Rating"] = Settings->GetInt("ImageRating");
AXmpData["Xmp.xmp.Rating"] = Settings->GetInt("ImageRating");
// Program name
outExifData["Exif.Image.ProcessingSoftware"] = ProgramName;
outExifData["Exif.Image.Software"] = ProgramName;
AIptcData["Iptc.Application2.Program"] = ProgramName;
AIptcData["Iptc.Application2.ProgramVersion"] = "idle";
AXmpData["Xmp.xmp.CreatorTool"] = ProgramName;
AXmpData["Xmp.tiff.Software"] = ProgramName;
// Title
QString TitleWorking = Settings->GetString("ImageTitle");
StringClean(TitleWorking);
//.........这里部分代码省略.........
示例12: 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;
}
示例13: exifTagData
// [Private]
//
// Exif.GPSInfo.GPSLatitudeRef (Ascii)
// Indicates whether the latitude is north or south latitude.
// The ASCII value 'N' indicates north latitude, and 'S' is south latitude.
//
// Exif.GpsInfo.GPSLatitude (Rational)
// Indicates the latitude. The latitude is expressed as three RATIONAL values
// giving the degrees, minutes, and seconds, respectively.
// When degrees, minutes and seconds are expressed, the format is dd/1,mm/1,ss/1.
// When degrees and minutes are used and, for example, fractions of minutes
// are given up to two decimal places, the format is dd/1,mmmm/100,0/1.
//
// Exif.GPSInfo.GPSLongitudeRef (Ascii)
// Indicates whether the longitude is east or west longitude.
// ASCII 'E' indicates east longitude, and 'W' is west longitude.
//
// Exif.GPSInfo.GPSLongitude (Rational)
// Indicates the longitude. The longitude is expressed as three RATIONAL values
// giving the degrees, minutes, and seconds, respectively.
// When degrees, minutes and seconds are expressed, the format is ddd/1,mm/1,ss/1.
// When degrees and minutes are used and, for example, fractions of minutes are
// given up to two decimal places, the format is ddd/1,mmmm/100,0/1.
//
bool QExiv2::exifGpsCoordinate(const QString &coordTag, const QString &refTag, double *value) const
{
const QByteArray ref = exifTagData(refTag.toLatin1().constData());
if (ref.isEmpty()) {
return false;
}
bool dir = false;
switch (ref[0]) {
case 'N':
case 'E':
break;
case 'S':
case 'W':
dir = true;
break;
default:
qWarning() << Q_FUNC_INFO << "Invalid Ref. data:" << ref[0];
return false;
}
double degrees;
const Exiv2::ExifKey key(coordTag.toLatin1().constData());
const Exiv2::ExifData data(d->exifMetadata);
Exiv2::ExifData::const_iterator it = data.findKey(key);
if (it != data.end() && (*it).count() == 3) {
// Latitude decoding from Exif.
double num;
double den;
// .toRational(long n) Return the n-th component of the value converted
// to Rational. The return value is -1/1 if the value is not set and the
// behaviour of the method is undefined if there is no n-th component.
num = (double)((*it).toRational(0).first);
den = (double)((*it).toRational(0).second);
if (den == 0) {
return false;
}
degrees = num/den;
// Calc minutes
num = (double)((*it).toRational(1).first);
den = (double)((*it).toRational(1).second);
if (den == 0) {
return false;
}
double v;
v = num/den;
if (v != -1.0) {
degrees += v / 60.0;
}
// Calc seconds
num = (double)((*it).toRational(2).first);
den = (double)((*it).toRational(2).second);
if (den == 0) {
// Accept 0/0 seconds.
if (num == 0) {
den = 1;
} else {
return false;
}
}
v = num/den;
if (v != -1.0) {
degrees += v / 3600.0;
}
if (dir) {
degrees *= -1.0;
}
*value = degrees;
return true;
//.........这里部分代码省略.........
示例14: GetNaturalRotation
long GalleryUtil::GetNaturalRotation(const QString &filePathString)
{
long rotateAngle = 0;
#ifdef EXIF_SUPPORT
QByteArray filePathBA = filePathString.toLocal8Bit();
const char *filePath = filePathBA.constData();
try
{
char *exifvalue = new char[1024];
ExifData *data = exif_data_new_from_file (filePath);
if (data)
{
for (int i = 0; i < EXIF_IFD_COUNT; i++)
{
ExifEntry *entry = exif_content_get_entry (data->ifd[i],
EXIF_TAG_ORIENTATION);
ExifByteOrder byteorder = exif_data_get_byte_order (data);
if (entry)
{
ExifShort v_short = exif_get_short (entry->data, byteorder);
VERBOSE(VB_GENERAL|VB_EXTRA, QString("Exif entry=%1").arg(v_short));
/* See http://sylvana.net/jpegcrop/exif_orientation.html*/
if (v_short == 8)
{
rotateAngle = -90;
}
else if (v_short == 6)
{
rotateAngle = 90;
}
break;
}
}
exif_data_free(data);
}
else
{
VERBOSE(VB_FILE, LOC_ERR +
QString("Could not load exif data from '%1'")
.arg(filePath));
}
delete [] exifvalue;
#if 0
Exiv2::ExifData exifData;
int rc = exifData.read(filePath);
if (!rc)
{
Exiv2::ExifKey key = Exiv2::ExifKey("Exif.Image.Orientation");
Exiv2::ExifData::iterator pos = exifData.findKey(key);
if (pos != exifData.end())
{
long orientation = pos->toLong();
switch (orientation)
{
case 6:
rotateAngle = 90;
break;
case 8:
rotateAngle = -90;
break;
default:
rotateAngle = 0;
break;
}
}
}
#endif
}
catch (...)
{
VERBOSE(VB_IMPORTANT, LOC_ERR +
QString("Failed to extract EXIF headers from '%1'")
.arg(filePathString));
}
#else
// Shut the compiler up about the unused argument
(void)filePathString;
#endif // EXIF_SUPPORT
return rotateAngle;
}
示例15: ReadExif
bool ptImageHelper::ReadExif(const QString &AFileName,
Exiv2::ExifData &AExifData,
std::vector<uint8_t> &AExifBuffer)
{
if (AFileName.trimmed().isEmpty()) return false;
try {
if (Exiv2::ImageFactory::getType(AFileName.toLocal8Bit().data()) == Exiv2::ImageType::none)
return false;
Exiv2::Image::AutoPtr hImage = Exiv2::ImageFactory::open(AFileName.toLocal8Bit().data());
if (!hImage.get()) return false;
hImage->readMetadata();
AExifData = hImage->exifData();
if (AExifData.empty()) {
ptLogWarning(ptWarning_Argument, "No Exif data found in %s", AFileName.toLocal8Bit().data());
return false;
}
Exiv2::ExifData::iterator Pos;
size_t Size;
#if EXIV2_TEST_VERSION(0,17,91) /* Exiv2 0.18-pre1 */
Exiv2::Blob Blob;
Exiv2::ExifParser::encode(Blob, Exiv2::bigEndian, AExifData);
Size = Blob.size();
#else
Exiv2::DataBuf Buf(AExifData.copy());
Size = Buf.size_;
#endif
/* If buffer too big for JPEG, try deleting some stuff. */
if (Size + CExifHeader.size() > CMaxHeaderLength) {
if ((Pos = AExifData.findKey(Exiv2::ExifKey("Exif.Photo.MakerNote"))) != AExifData.end() ) {
AExifData.erase(Pos);
ptLogWarning(ptWarning_Argument, "Exif buffer too big, erasing Exif.Photo.MakerNote");
#if EXIV2_TEST_VERSION(0,17,91) /* Exiv2 0.18-pre1 */
Exiv2::ExifParser::encode(Blob, Exiv2::bigEndian, AExifData);
Size = Blob.size();
#else
Buf = AExifData.copy();
Size = Buf.size_;
#endif
}
}
// Erase embedded thumbnail if needed
if (Settings->GetInt("EraseExifThumbnail") ||
(Size + CExifHeader.size()) > CMaxHeaderLength ) {
#if EXIV2_TEST_VERSION(0,17,91) /* Exiv2 0.18-pre1 */
Exiv2::ExifThumb Thumb(AExifData);
Thumb.erase();
#else
AExifData.eraseThumbnail();
#endif
if (!Settings->GetInt("EraseExifThumbnail"))
ptLogWarning(ptWarning_Argument, "Exif buffer too big, erasing Thumbnail");
#if EXIV2_TEST_VERSION(0,17,91) /* Exiv2 0.18-pre1 */
Exiv2::ExifParser::encode(Blob, Exiv2::bigEndian, AExifData);
Size = Blob.size();
#else
Buf = AExifData.copy();
Size = Buf.size_;
#endif
}
AExifBuffer.clear();
AExifBuffer.insert(AExifBuffer.end(),
CExifHeader.begin(),
CExifHeader.end());
#if EXIV2_TEST_VERSION(0,17,91) /* Exiv2 0.18-pre1 */
AExifBuffer.insert(AExifBuffer.end(),
Blob.begin(),
Blob.end());
#else
// old code will currently not compile
memcpy(AExifBuffer+sizeof(ExifHeader), Buf.pData_, Buf.size_);
#endif
return true;
} catch(Exiv2::Error& Error) {
// Exiv2 errors are in this context hopefully harmless
// (unsupported tags etc.)
ptLogWarning(ptWarning_Exiv2,"Exiv2 : %s\n",Error.what());
}
return false;
}