本文整理汇总了C++中image::AutoPtr::writeMetadata方法的典型用法代码示例。如果您正苦于以下问题:C++ AutoPtr::writeMetadata方法的具体用法?C++ AutoPtr::writeMetadata怎么用?C++ AutoPtr::writeMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image::AutoPtr
的用法示例。
在下文中一共展示了AutoPtr::writeMetadata方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// *****************************************************************************
// Main
int main(int argc, char* const argv[])
{
try {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " image\n";
std::cout << "Commands read from stdin.\n";
return 1;
}
Image::AutoPtr image = ImageFactory::open(argv[1]);
assert (image.get() != 0);
image->readMetadata();
// Process commands
std::string line;
int num = 0;
std::getline(std::cin, line);
while (line.length() && processLine(line, ++num, image->iptcData())) {
std::getline(std::cin, line);
}
// Save any changes
image->writeMetadata();
return 0;
}
catch (AnyError& e) {
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}
}
示例2: erase
int IptcData::erase(const std::string& path) const
{
if (!fileExists(path, true)) return -1;
Image::AutoPtr image = ImageFactory::instance().open(path);
if (image.get() == 0) return -2;
// Read all metadata then erase only Iptc data
int rc = image->readMetadata();
if (rc == 0) {
image->clearIptcData();
rc = image->writeMetadata();
}
return rc;
} // IptcData::erase
示例3: write
int IptcData::write(const std::string& path)
{
// Remove the Iptc section from the file if there is no metadata
if (count() == 0) return erase(path);
if (!fileExists(path, true)) return -1;
Image::AutoPtr image = ImageFactory::instance().open(path);
if (image.get() == 0) return -2;
DataBuf buf(copy());
// Read all metadata to preserve non-Iptc data
int rc = image->readMetadata();
if (rc == 0) {
image->setIptcData(buf.pData_, buf.size_);
rc = image->writeMetadata();
}
return rc;
} // IptcData::write
示例4: doWriteMetadata
void PgfImage::doWriteMetadata(BasicIo& outIo)
{
if (!io_->isopen()) throw Error(20);
if (!outIo.isopen()) throw Error(21);
#ifdef DEBUG
std::cout << "Exiv2::PgfImage::doWriteMetadata: Writing PGF file " << io_->path() << "\n";
std::cout << "Exiv2::PgfImage::doWriteMetadata: tmp file created " << outIo.path() << "\n";
#endif
// Ensure that this is the correct image type
if (!isPgfType(*io_, true))
{
if (io_->error() || io_->eof()) throw Error(20);
throw Error(22);
}
// Ensure PGF version.
byte mnb = readPgfMagicNumber(*io_);
readPgfHeaderSize(*io_);
int w, h;
DataBuf header = readPgfHeaderStructure(*io_, w, h);
Image::AutoPtr img = ImageFactory::create(ImageType::png);
img->setExifData(exifData_);
img->setIptcData(iptcData_);
img->setXmpData(xmpData_);
img->writeMetadata();
int imgSize = img->io().size();
DataBuf imgBuf = img->io().read(imgSize);
#ifdef DEBUG
std::cout << "Exiv2::PgfImage::doWriteMetadata: Creating image to host metadata (" << imgSize << " bytes)\n";
#endif
//---------------------------------------------------------------
// Write PGF Signature.
if (outIo.write(pgfSignature, 3) != 3) throw Error(21);
// Write Magic number.
if (outIo.putb(mnb) == EOF) throw Error(21);
// Write new Header size.
uint32_t newHeaderSize = header.size_ + imgSize;
DataBuf buffer(4);
memcpy (buffer.pData_, &newHeaderSize, 4);
byteSwap_(buffer,0,bSwap_);
if (outIo.write(buffer.pData_, 4) != 4) throw Error(21);
#ifdef DEBUG
std::cout << "Exiv2::PgfImage: new PGF header size : " << newHeaderSize << " bytes\n";
printf("%x\n", buffer.pData_[0]);
printf("%x\n", buffer.pData_[1]);
printf("%x\n", buffer.pData_[2]);
printf("%x\n", buffer.pData_[3]);
#endif
// Write Header data.
if (outIo.write(header.pData_, header.size_) != header.size_) throw Error(21);
// Write new metadata byte array.
if (outIo.write(imgBuf.pData_, imgBuf.size_) != imgBuf.size_) throw Error(21);
// Copy the rest of PGF image data.
DataBuf buf(4096);
long readSize = 0;
while ((readSize=io_->read(buf.pData_, buf.size_)))
{
if (outIo.write(buf.pData_, readSize) != readSize) throw Error(21);
}
if (outIo.error()) throw Error(21);
} // PgfImage::doWriteMetadata