本文整理汇总了C++中exiv2::image::AutoPtr::writeMetadata方法的典型用法代码示例。如果您正苦于以下问题:C++ AutoPtr::writeMetadata方法的具体用法?C++ AutoPtr::writeMetadata怎么用?C++ AutoPtr::writeMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exiv2::image::AutoPtr
的用法示例。
在下文中一共展示了AutoPtr::writeMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: saveExifGps
void ExifReaderWriter::saveExifGps(QString pictureName, double latitude, double longitude, double altitude)
{
qDebug() << "saveExifGps" << pictureName << latitude << longitude << altitude;
Exiv2::Image::AutoPtr image = openExif(pictureName);
if(image.get() == 0)
return;
if(image->exifData().empty())
{
Exiv2::ExifData exifDataTmp;
image->setExifData(exifDataTmp);
}
Exiv2::ExifData &exifData = image->exifData();
writeData(exifData, "Exif.GPSInfo.GPSLatitude", exifLatLonString(latitude));
writeData(exifData, "Exif.GPSInfo.GPSLongitude", exifLatLonString(longitude));
writeData(exifData, "Exif.GPSInfo.GPSLatitudeRef", (latitude<0 ? "S" : "N"));
writeData(exifData, "Exif.GPSInfo.GPSLongitudeRef", (longitude<0 ? "W" : "E"));
if(altitude > -999)
{
writeData(exifData, "Exif.GPSInfo.GPSAltitude", (QString("%1/%2").arg(abs(round(altitude * 1000))).arg(1000)));
writeData(exifData, "Exif.GPSInfo.GPSAltitudeRef", (altitude<0 ? "1" : "0"));
}
image->writeMetadata();
}
示例3: 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;
}
示例4: write
void write(const std::string& file, Exiv2::ExifData& ed)
{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
assert (image.get() != 0);
image->setExifData(ed);
image->writeMetadata();
}
示例5: 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;
}
}
示例6: 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;
}
示例7: 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;
}
}
示例8: 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();
}
示例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: saveExifData
// Saves Exifdata to given file
void FlickrUpload::saveExifData(Exiv2::ExifData *exifData, QByteArray *image){
try {
Exiv2::Image::AutoPtr destImage = Exiv2::ImageFactory::open(
(Exiv2::byte*)image->constData(), (long)image->size());
destImage->setExifData(*exifData);
destImage->writeMetadata();
// get updated image data
Exiv2::BasicIo& rawio = destImage->io();
Exiv2::DataBuf dbuf = rawio.read( rawio.size() );
image->clear();
image->append(QByteArray::fromRawData((char*)dbuf.pData_, dbuf.size_));
} catch (Exiv2::Error& e) {
qCritical("[SaveFile] %s", e.what());
}
}
示例11: saveImage
void ImageView::saveImage()
{
Exiv2::Image::AutoPtr image;
bool exifError = false;
if (newImage)
{
saveImageAs();
return;
}
setFeedback(tr("Saving..."));
try
{
image = Exiv2::ImageFactory::open(currentImageFullPath.toStdString());
image->readMetadata();
}
catch (Exiv2::Error &error)
{
exifError = true;
}
QImageReader imgReader(currentImageFullPath);
if (!displayPixmap.save(currentImageFullPath, imgReader.format().toUpper(),
GData::defaultSaveQuality))
{
QMessageBox msgBox;
msgBox.critical(this, tr("Error"), tr("Failed to save image."));
return;
}
if (!exifError)
{
try
{
image->writeMetadata();
}
catch (Exiv2::Error &error)
{
QMessageBox msgBox;
msgBox.critical(this, tr("Error"), tr("Failed to save Exif metadata."));
}
}
reload();
setFeedback(tr("Image saved."));
}
示例12: main
// *****************************************************************************
// 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::ExifData &exifData = image->exifData();
/*
Exiv2 uses a CommentValue for Exif user comments. The format of the
comment string includes an optional charset specification at the beginning:
[charset=["]Ascii|Jis|Unicode|Undefined["] ]comment
Undefined is used as a default if the comment doesn't start with a charset
definition.
Following are a few examples of valid comments. The last one is written to
the file.
*/
exifData["Exif.Photo.UserComment"]
= "charset=\"Unicode\" An Unicode Exif comment added with Exiv2";
exifData["Exif.Photo.UserComment"]
= "charset=\"Undefined\" An undefined Exif comment added with Exiv2";
exifData["Exif.Photo.UserComment"]
= "Another undefined Exif comment added with Exiv2";
exifData["Exif.Photo.UserComment"]
= "charset=Ascii An ASCII Exif comment added with Exiv2";
std::cout << "Writing user comment '"
<< exifData["Exif.Photo.UserComment"]
<< "' back to the image\n";
image->writeMetadata();
return 0;
}
catch (Exiv2::AnyError& e) {
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}
示例13: saveImageAs
void ImageView::saveImageAs()
{
Exiv2::Image::AutoPtr exifImage;
Exiv2::Image::AutoPtr newExifImage;
bool exifError = false;
setCursorHiding(false);
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save image as"),
currentImageFullPath,
tr("Images") + " (*.jpg *.jpeg *.jpe *.png *.bmp *.ppm *.pgm *.pbm *.xbm *.xpm)");
if (!fileName.isEmpty()) {
try {
exifImage = Exiv2::ImageFactory::open(currentImageFullPath.toStdString());
exifImage->readMetadata();
}
catch (Exiv2::Error &error) {
exifError = true;
}
if (!displayPixmap.save(fileName, 0, GData::defaultSaveQuality)) {
QMessageBox msgBox;
msgBox.critical(this, tr("Error"), tr("Failed to save image."));
} else {
if (!exifError) {
try {
newExifImage = Exiv2::ImageFactory::open(fileName.toStdString());
newExifImage->setMetadata(*exifImage);
newExifImage->writeMetadata();
}
catch (Exiv2::Error &error) {
exifError = true;
}
}
setFeedback(tr("Image saved."));
}
}
if (mainWindow->isFullScreen()) {
setCursorHiding(true);
}
}
示例14: copyExif
void ExifTools::copyExif(const QString &sourceStr, const QString &destStr)
{
Exiv2::Image::AutoPtr sourceImageData =
Exiv2::ImageFactory::open(QFile::encodeName(sourceStr).data());
sourceImageData->readMetadata();
Exiv2::ExifData exifData = sourceImageData->exifData();
Exiv2::IptcData iptcData = sourceImageData->iptcData();
Exiv2::ExifThumb exifThumb(exifData);
exifThumb.erase();
Exiv2::Image::AutoPtr destImageData =
Exiv2::ImageFactory::open(QFile::encodeName(destStr).data());
destImageData->setExifData(exifData);
destImageData->setIptcData(iptcData);
destImageData->writeMetadata();
}
示例15: writeTagsToImage
bool ImageTags::writeTagsToImage(QString &imageFileName, QSet<QString> &newTags)
{
QSet<QString> imageTags;
Exiv2::Image::AutoPtr exifImage;
try {
exifImage = Exiv2::ImageFactory::open(imageFileName.toStdString());
exifImage->readMetadata();
Exiv2::IptcData newIptcData;
/* copy existing data */
Exiv2::IptcData &iptcData = exifImage->iptcData();
if (!iptcData.empty()) {
QString key;
Exiv2::IptcData::iterator end = iptcData.end();
for (Exiv2::IptcData::iterator iptcIt = iptcData.begin(); iptcIt != end; ++iptcIt) {
if (iptcIt->tagName() != "Keywords") {
newIptcData.add(*iptcIt);
}
}
}
/* add new tags */
QSetIterator<QString> newTagsIt(newTags);
while (newTagsIt.hasNext()) {
QString tag = newTagsIt.next();
Exiv2::Value::AutoPtr value = Exiv2::Value::create(Exiv2::string);
value->read(tag.toStdString());
Exiv2::IptcKey key("Iptc.Application2.Keywords");
newIptcData.add(key, value.get());
}
exifImage->setIptcData(newIptcData);
exifImage->writeMetadata();
}
catch (Exiv2::Error &error) {
QMessageBox msgBox;
msgBox.critical(this, tr("Error"), tr("Failed to save tags to ") + imageFileName);
return false;
}
return true;
}