Writing offset information to a PNG file

  • I think I'm misreading the documentation.....but it seems like the offset information should be automatically written to a png file when using QImage::Save(). I also believe that PNG is spec'd to store offset information. What is the easiest way to save a QImage to a file and save the offset information?

    void saveImg()
    QImage img("c:/myImg.png");
    img.setOffset(QPoint(100, 100));

    void openImg()
    QImage img("c:/offset.png");
    qDebug()<<"offset = "<<img.offset();

    ///results offset = QPoint(0,0);
    /// I have verified that oFFs is blank in the file....oFFs is where the offset is supposed to be stored


  • On Qt 4.8.4 and Qt 5.1.0 on Linux the offset is written to the PNG file, but it is not preserved when read by QImage.

    #include <QApplication>
    #include <QImage>
    #include <QDebug>

    int main(int argc, char **argv) {
    QApplication app(argc, argv);
    QImage img(256, 256, QImage::Format_ARGB32);
    img.setOffset(QPoint(17, 37));
    qDebug() << "Before save" << img.offset();
    QImage img2("test.png");
    qDebug() << "After load" << img2.offset();
    return 0;
    Before save QPoint(17,37)
    After load QPoint(0,0)
    Also, the PNG contains the offset:
    $ identify test.png
    test.png PNG 256x256 256x256+17+37 8-bit DirectClass 63.6KB 0.000u 0:00.000

  • Lifetime Qt Champion

    After a quick check, it might be a "missing feature" from the png plugin

  • Thanks ChrisW67 and SGaist for your responses.

  • Moderators

    you may want to create a bug report for this missing feature on https://bugreports.qt-project.org

  • As a workaround, I used QImageWriter to write the offset to my image file. Of course this is only good for my application and is not transportable.

    @ QImage image("image.png");
    image.setOffset(10, 10);
    QImageWriter writer("outimage.png", "png");
    writer.setText("offsetX", QString::number(image.offset().x()));
    writer.setText("offsetY", QString::number(image.offset().y()));

  • Lifetime Qt Champion

  • Lifetime Qt Champion

    Patches have been merged for both Qt 4 and 5

Log in to reply

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