コード例 #1
0
ファイル: ptImageHelper.cpp プロジェクト: divyang4481/photivo
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;
}
コード例 #2
0
ファイル: imageview.cpp プロジェクト: vfrenkel/phototonic
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);
	}
}