Ejemplo n.º 1
0
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;
    }
}
Ejemplo n.º 2
0
// 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());
    }
}
Ejemplo n.º 3
0
bool JpegContent::save(QIODevice* device)
{
    if (!d->mImage.isNull()) {
        if (!d->updateRawDataFromImage()) {
            return false;
        }
    }

    if (d->mRawData.size() == 0) {
        d->mErrorString = i18nc("@info", "No data to store.");
        return false;
    }

    if (d->mPendingTransformation) {
        applyPendingTransformation();
        d->mPendingTransformation = false;
    }

    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open((unsigned char*)d->mRawData.data(), d->mRawData.size());

    // Store Exif info
    image->setExifData(d->mExifData);
    image->setComment(d->mComment.toUtf8().data());
    image->writeMetadata();

    // Update mRawData
    Exiv2::BasicIo& io = image->io();
    d->mRawData.resize(io.size());
    io.read((unsigned char*)d->mRawData.data(), io.size());

    QDataStream stream(device);
    stream.writeRawData(d->mRawData.data(), d->mRawData.size());

    // Make sure we are up to date
    loadFromData(d->mRawData);
    return true;
}