QImageWriter and EXIF

  • Hi,

    I used QImageReader to read image from file and QImageWriter to save imge to file. The issue is that when I save image to file using QImageWriter, it looses EXI
    F information of image. Is there any way in Qt I don't loose EXIF information when I save image to file?

  • Lifetime Qt Champion


    There was at some point the QExifImageHeader class that might be of interest.

  • @SGaist
    Thanks, I have checked it, but there seems some bug for Gps info. For example, when I run following code, I think exif values should not change.

        QExifImageHeader header;
        QExifValue value_GpsLatitude = header.value(QExifImageHeader::GpsLatitude);
        QExifValue value_ImageWidth = header.value(QExifImageHeader::ImageWidth);
        QExifValue value_Make = header.value(QExifImageHeader::Make);
        QExifValue value_Model = header.value(QExifImageHeader::Model);
        header.setValue(QExifImageHeader::GpsLatitude, value_GpsLatitude);
        header.setValue(QExifImageHeader::ImageWidth, value_ImageWidth);
        header.setValue(QExifImageHeader::Make, value_Make);
        header.setValue(QExifImageHeader::Model, value_Model);

    But when I run it, GpsLatitude value has changed. Do you think it is a bug?
    And how can I read GpsLatitude?
    When I run the following,

       qDebug()<<"laa: "<< QString::number(value_GpsLatitude.toRational().first)+"/"+QString::number(value_GpsLatitude.toRational().second);

    I always get "0/0" which is not correct.

  • @samdol what about this EXIF helper code?

  • Lifetime Qt Champion

    Might be, I can't confirm, I don't have images containing such data to test.

  • @Pablo-J.-Rogina
    Thank you, I used it before. but it only reads exif information. Because I want to preserve EXIF after save image, I need a method to read/write exif.

  • @SGaist
    I found that Reading Gps information should be like this,

      qDebug()<<"laa: "<< QString::number(value_GpsLatitude.toRationalVector().at(0).first)+"/"+QString::number(value_GpsLatitude.toRationalVector().at(0).second);
      qDebug()<<"laa: "<< QString::number(value_GpsLatitude.toRationalVector().at(1).first)+"/"+QString::number(value_GpsLatitude.toRationalVector().at(1).second);
      qDebug()<<"laa: "<< QString::number(value_GpsLatitude.toRationalVector().at(2).first)+"/"+QString::number(value_GpsLatitude.toRationalVector().at(2).second);

    But I still don't understand why it changes Gps value after


    It changes even without

    header.setValue(QExifImageHeader::GpsLatitude, value_GpsLatitude);

    It seems a bug.
    You may get test jpg file with gps_tag from here

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.