本文整理汇总了C++中exiv2::image::AutoPtr::readMetadata方法的典型用法代码示例。如果您正苦于以下问题:C++ AutoPtr::readMetadata方法的具体用法?C++ AutoPtr::readMetadata怎么用?C++ AutoPtr::readMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exiv2::image::AutoPtr
的用法示例。
在下文中一共展示了AutoPtr::readMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copyMetadata
void ExifTransfer::copyMetadata() {
try {
dst = Exiv2::ImageFactory::open(BasicIo::AutoPtr(new MemIo(data, dataSize)));
dst->readMetadata();
} catch (Exiv2::Error & e) {
std::cerr << "Exiv2 error: " << e.what() << std::endl;
return;
}
try {
src = Exiv2::ImageFactory::open(srcFile.toLocal8Bit().constData());
src->readMetadata();
copyXMP();
copyIPTC();
copyEXIF();
} catch (Exiv2::Error & e) {
std::cerr << "Exiv2 error: " << e.what() << std::endl;
// At least we have to set the SubImage1 file type to Primary Image
dst->exifData()["Exif.SubImage1.NewSubfileType"] = 0;
}
try {
dst->writeMetadata();
FileIo fileIo(dstFile.toLocal8Bit().constData());
fileIo.open("wb");
fileIo.write(dst->io());
fileIo.close();
} catch (Exiv2::Error & e) {
std::cerr << "Exiv2 error: " << e.what() << std::endl;
}
}
示例2: main
// *****************************************************************************
// Main
int main(int argc, char* const argv[])
{
try {
// Handle command line arguments
Params params;
if (params.getopt(argc, argv)) {
params.usage();
return 1;
}
if (params.help_) {
params.help();
return 2;
}
// Use MemIo to increase test coverage.
Exiv2::BasicIo::AutoPtr fileIo(new Exiv2::FileIo(params.read_));
Exiv2::BasicIo::AutoPtr memIo(new Exiv2::MemIo);
memIo->transfer(*fileIo);
Exiv2::Image::AutoPtr readImg = Exiv2::ImageFactory::open(memIo);
assert(readImg.get() != 0);
readImg->readMetadata();
Exiv2::Image::AutoPtr writeImg = Exiv2::ImageFactory::open(params.write_);
assert(writeImg.get() != 0);
if (params.preserve_) writeImg->readMetadata();
if (params.iptc_) {
writeImg->setIptcData(readImg->iptcData());
}
if (params.exif_) {
writeImg->setExifData(readImg->exifData());
}
if (params.comment_) {
writeImg->setComment(readImg->comment());
}
if (params.xmp_) {
writeImg->setXmpData(readImg->xmpData());
}
try {
writeImg->writeMetadata();
}
catch (const Exiv2::AnyError&) {
std::cerr << params.progname() <<
": Could not write metadata to (" << params.write_ << ")\n";
return 8;
}
return 0;
}
catch (Exiv2::AnyError& e) {
std::cerr << "Caught Exiv2 exception '" << e << "'\n";
return 10;
}
}
示例3: populateMetaExif
int populateMetaExif(std::string file, std::string plate)
{
try
{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
std::string comment = plate + ' '+ "LOT50"; //Add code to get information about lot
if(!image.get())
{
throw Exiv2::Error(1, "Failed to open image");
}
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
exifData["Exif.Photo.UserComment"]= comment;
//std::cout<< "Writing Exiv User Comment "<< exifData["Exif.Image.ImageDescription"] <<"\n";
image->writeMetadata();
} catch (Exiv2::AnyError& e) {
std::cout << "Problem Writing Metadata '" << e << "'\n";
return -1;
}
return 0;
}
示例4: getExifFromPath
Exiv2::ExifData getExifFromPath(char* filename) {
qDebug() << "Trying to read EXIF for" << filename;
try {
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
assert(image.get() != 0);
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
if (exifData.empty()) {
std::string error(filename);
error += ": No Exif data found in the file";
//TODO Translate
//throw Exiv2::Error(1, error);
}
return exifData;
} catch (Exiv2::Error& e) {
Exiv2::ExifData exifData;
qCritical() << "Caught Exiv2 exception '" << e.what();
//TODO Translate
return exifData;
}
}
示例5: print
void print(const std::string& file)
{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
assert(image.get() != 0);
image->readMetadata();
Exiv2::ExifData &ed = image->exifData();
Exiv2::ExifData::const_iterator end = ed.end();
for (Exiv2::ExifData::const_iterator i = ed.begin(); i != end; ++i) {
std::cout << std::setw(45) << std::setfill(' ') << std::left
<< i->key() << " "
<< "0x" << std::setw(4) << std::setfill('0') << std::right
<< std::hex << i->tag() << " "
<< std::setw(12) << std::setfill(' ') << std::left
<< i->ifdName() << " "
<< std::setw(9) << std::setfill(' ') << std::left
<< i->typeName() << " "
<< std::dec << std::setw(3)
<< std::setfill(' ') << std::right
<< i->count() << " "
<< std::dec << i->value()
<< "\n";
}
}
示例6: main
int main(int argc, char* const argv[])
try {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " file\n";
return 1;
}
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]);
assert(image.get() != 0);
image->readMetadata();
const std::string& xmpPacket = image->xmpPacket();
if (xmpPacket.empty()) {
std::string error(argv[1]);
error += ": No XMP packet found in the file";
throw Exiv2::Error(1, error);
}
std::cout << xmpPacket << "\n";
return 0;
}
catch (Exiv2::AnyError& e) {
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}
示例7: TransferExif
bool ptImageHelper::TransferExif(const QString ASourceFile, const QString ATargetFile)
{
if (ASourceFile == ATargetFile ||
ASourceFile.trimmed().isEmpty() ||
ATargetFile.trimmed().isEmpty())
return false;
try {
if (Exiv2::ImageFactory::getType(ASourceFile.toLocal8Bit().data()) == Exiv2::ImageType::none)
return false;
Exiv2::Image::AutoPtr hSourceImage = Exiv2::ImageFactory::open(ASourceFile.toLocal8Bit().data());
if (!hSourceImage.get()) return false;
hSourceImage->readMetadata();
Exiv2::Image::AutoPtr hTargetImage = Exiv2::ImageFactory::open(ATargetFile.toLocal8Bit().data());
hTargetImage->clearMetadata();
hTargetImage->setMetadata(*hSourceImage);
hTargetImage->writeMetadata();
return true;
} catch (Exiv2::AnyError& Error) {
if (Settings->GetInt("JobMode") == 0) {
ptMessageBox::warning(0 ,"Exiv2 Error","No exif data written!\nCaught Exiv2 exception '" + QString(Error.what()) + "'\n");
} else {
std::cout << "Caught Exiv2 exception '" << Error << "'\n";
}
}
return false;
}
示例8: main
int main(int argc, char* const argv[])
try {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " file\n";
return 1;
}
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]);
assert(image.get() != 0);
image->readMetadata();
Exiv2::XmpData xmpData;
Exiv2::copyExifToXmp(image->exifData(), xmpData);
Exiv2::ExifData exifData;
Exiv2::copyXmpToExif(xmpData, exifData);
image->setXmpData(xmpData);
image->setExifData(exifData);
image->writeMetadata();
return 0;
}
catch (Exiv2::AnyError& e) {
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}
示例9: RemoveGPSExif
int RemoveGPSExif(const char* File, int NoChangeMtime)
{
struct stat statbuf;
struct stat statbuf2;
struct utimbuf utb;
if (NoChangeMtime)
stat(File, &statbuf);
// Open the file and start reading.
Exiv2::Image::AutoPtr Image;
try {
Image = Exiv2::ImageFactory::open(File);
} catch (Exiv2::Error e) {
DEBUGLOG("Failed to open file %s.\n", File);
return 0;
}
Image->readMetadata();
if (Image.get() == NULL)
{
// It failed if we got here.
DEBUGLOG("Failed to read file %s %s.\n",
File, Exiv2::strError().c_str());
return 0;
}
Exiv2::ExifData &ExifInfo = Image->exifData();
if (ExifInfo.count() == 0)
{
DEBUGLOG("No EXIF tags in file %s.\n", File);
return 0;
}
EraseGpsTags(ExifInfo);
try {
Image->writeMetadata();
} catch (Exiv2::Error e) {
DEBUGLOG("Failed to write to file %s.\n", File);
return 0;
}
if (NoChangeMtime)
{
stat(File, &statbuf2);
utb.actime = statbuf2.st_atime;
utb.modtime = statbuf.st_mtime;
utime(File, &utb);
}
return 1;
}
示例10: loadCamXyzFromDng
void RawParameters::loadCamXyzFromDng() {
// Try to load it from the DNG metadata
try {
const float d65_white[3] = { 0.950456f, 1.0f, 1.088754f };
double cc[4][4], xyz[] = { 1,1,1 };
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
cc[j][i] = i == j ? 1.0 : 0.0;
}
}
Exiv2::Image::AutoPtr src = Exiv2::ImageFactory::open(fileName.toLocal8Bit().constData());
src->readMetadata();
const Exiv2::ExifData & srcExif = src->exifData();
auto ccData = srcExif.findKey(Exiv2::ExifKey("Exif.Image.CameraCalibration1"));
if (ccData == srcExif.end()) {
ccData = srcExif.findKey(Exiv2::ExifKey("Exif.Image.CameraCalibration2"));
}
if (ccData != srcExif.end()) {
for (int i = 0; i < colors; ++i) {
for (int j = 0; j < colors; ++j) {
cc[i][j] = ccData->toFloat(i*colors + j);
}
}
}
auto xyzData = srcExif.findKey(Exiv2::ExifKey("Exif.Image.AsShotWhiteXY"));
if (xyzData != srcExif.end()) {
xyz[0] = xyzData->toFloat(0);
xyz[1] = xyzData->toFloat(1);
xyz[2] = 1.0 - xyz[0] - xyz[1];
for (int i = 0; i < 3; ++i) {
xyz[i] /= d65_white[i];
}
}
auto cmData = srcExif.findKey(Exiv2::ExifKey("Exif.Image.ColorMatrix1"));
if (cmData == srcExif.end()) {
cmData = srcExif.findKey(Exiv2::ExifKey("Exif.Image.ColorMatrix2"));
}
if (cmData != srcExif.end() && cmData->count() == 3*colors) {
for (int c = 0; c < colors; ++c) {
for (int i = 0; i < 3; ++i) {
camXyz[c][i] = 0.0;
for (int j = 0; j < colors; ++j) {
camXyz[c][i] += cc[c][j] * cmData->toFloat(j*3 + i) * xyz[i];
}
}
}
}
} catch (Exiv2::Error & e) {
Log::debug("Could not load camXyz values from metadata: ", e.what());
}
}
示例11: save
void Frame::save(std::string dir) {
std::string path = dir + "/" + id;
imwrite(path, *img);
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path);
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
std::stringstream ss;
ss << std::setprecision(12) << data.lat << " " << data.lon << " " << data.altitude << " " << data.heading << " " << data.time;
exifData["Exif.Photo.UserComment"] = ss.str();
image->writeMetadata();
}
示例12: ReadExifDate
char* ReadExifDate(const char* File, int* IncludesGPS)
{
// Open and read the file.
Exiv2::Image::AutoPtr Image;
try {
Image = Exiv2::ImageFactory::open(File);
} catch (Exiv2::Error e) {
DEBUGLOG("Failed to open file %s.\n", File);
return NULL;
}
Image->readMetadata();
if (Image.get() == NULL)
{
DEBUGLOG("Failed to read file %s %s.\n",
File, Exiv2::strError().c_str());
return NULL;
}
Exiv2::ExifData &ExifRead = Image->exifData();
// Read the tag out.
Exiv2::Exifdatum& Tag = ExifRead["Exif.Photo.DateTimeOriginal"];
// Check that the tag is not blank.
std::string Value = Tag.toString();
if (Value.length() == 0)
{
// No date/time stamp.
// Not good.
// Just return - above us will handle it.
return NULL;
}
// Copy the tag and return that.
char* Copy = strdup(Value.c_str());
// Check if we have GPS tags.
Exiv2::Exifdatum& GPSData = ExifRead["Exif.GPSInfo.GPSLatitude"];
if (GPSData.count() < 3)
{
// No valid GPS data.
*IncludesGPS = 0;
} else {
// Seems to include GPS data...
*IncludesGPS = 1;
}
// Now return, passing a pointer to the date string.
return Copy; // It's up to the caller to free this.
}
示例13: catch
// Reads metadata from given file
Exiv2::ExifData *FlickrDownload::readExifData(QString file){
try{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(
file.toStdString().c_str());
image->readMetadata();
Exiv2::ExifData *data = new Exiv2::ExifData();
*data = image->exifData();
return data;
} catch (Exiv2::Error& e) {
qCritical("[Filechooser] %s", e.what());
return 0;
}
}
示例14: QSize
bool KExiv2::loadFromData(const QByteArray& imgData) const
{
if (imgData.isEmpty())
return false;
try
{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open((Exiv2::byte*)imgData.data(), imgData.size());
d->filePath.clear();
image->readMetadata();
// Size and mimetype ---------------------------------
d->pixelSize = QSize(image->pixelWidth(), image->pixelHeight());
d->mimeType = QString::fromLatin1(image->mimeType().c_str());
// Image comments ---------------------------------
d->imageComments() = image->comment();
// Exif metadata ----------------------------------
d->exifMetadata() = image->exifData();
// Iptc metadata ----------------------------------
d->iptcMetadata() = image->iptcData();
#ifdef _XMP_SUPPORT_
// Xmp metadata -----------------------------------
d->xmpMetadata() = image->xmpData();
#endif // _XMP_SUPPORT_
return true;
}
catch( Exiv2::Error& e )
{
d->printExiv2ExceptionError(QString::fromLatin1("Cannot load metadata using Exiv2 "), e);
}
catch(...)
{
qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
}
return false;
}
示例15: createProcessor
NegativeProcessor* NegativeProcessor::createProcessor(AutoPtr<dng_host> &host, const char *filename) {
// -----------------------------------------------------------------------------------------
// Open and parse rawfile with libraw...
AutoPtr<LibRaw> rawProcessor(new LibRaw());
int ret = rawProcessor->open_file(filename);
if (ret != LIBRAW_SUCCESS) {
rawProcessor->recycle();
std::stringstream error; error << "LibRaw-error while opening rawFile: " << libraw_strerror(ret);
throw std::runtime_error(error.str());
}
ret = rawProcessor->unpack();
if (ret != LIBRAW_SUCCESS) {
rawProcessor->recycle();
std::stringstream error; error << "LibRaw-error while unpacking rawFile: " << libraw_strerror(ret);
throw std::runtime_error(error.str());
}
// -----------------------------------------------------------------------------------------
// ...and libexiv2
Exiv2::Image::AutoPtr rawImage;
try {
rawImage = Exiv2::ImageFactory::open(filename);
rawImage->readMetadata();
}
catch (Exiv2::Error& e) {
std::stringstream error; error << "Exiv2-error while opening/parsing rawFile (code " << e.code() << "): " << e.what();
throw std::runtime_error(error.str());
}
// -----------------------------------------------------------------------------------------
// Identify and create correct processor class
if (rawProcessor->imgdata.idata.dng_version != 0) {
try {return new DNGprocessor(host, rawProcessor.Release(), rawImage);}
catch (dng_exception &e) {
std::stringstream error; error << "Cannot parse source DNG-file (code " << e.ErrorCode() << ")";
throw std::runtime_error(error.str());
}
}
else if (!strcmp(rawProcessor->imgdata.idata.model, "ILCE-7"))
return new ILCE7processor(host, rawProcessor.Release(), rawImage);
else if (!strcmp(rawProcessor->imgdata.idata.make, "FUJIFILM"))
return new FujiProcessor(host, rawProcessor.Release(), rawImage);
return new VariousVendorProcessor(host, rawProcessor.Release(), rawImage);
}