Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Writing offset information to a PNG file

Writing offset information to a PNG file

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jh224
    wrote on last edited by
    #1

    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));
    img.save("c:/offset.png");
    }

    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
    }

    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      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();
      img.save("test.png");
      QImage img2("test.png");
      qDebug() << "After load" << img2.offset();
      return 0;
      }
      @
      Output
      @
      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
      @

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jh224
          wrote on last edited by
          #4

          Thanks ChrisW67 and SGaist for your responses.

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

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

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jh224
              wrote on last edited by
              #6

              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()));
              writer.write(image);@

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Report "done":https://bugreports.qt-project.org/browse/QTBUG-32674

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Patches have been merged for both Qt 4 and 5

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved