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. QImage to byte array doesn't work
Forum Updated to NodeBB v4.3 + New Features

QImage to byte array doesn't work

Scheduled Pinned Locked Moved Unsolved General and Desktop
qimageimagebytearrayepdesp8266
5 Posts 4 Posters 2.1k 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.
  • G Offline
    G Offline
    Gh0stShell
    wrote on 16 Sept 2020, 12:36 last edited by Gh0stShell
    #1

    Hey,

    I try to get the raw Bytes from pictre from a QImage like

    QImage preview;
    QByteArray ba;
    QBuffer buffer(&ba);
    buffer.open(QIODevice::WriteOnly);
    qDebug() << "Saved: " << preview.save(&buffer);
    

    Yes, there is something in the QImage, I can display it.

    But save function returns a false.

    I need this to send a char array to my ESP8266 where use C so it can show the picture on an E-Paper Display

    P J 2 Replies Last reply 16 Sept 2020, 13:04
    0
    • G Gh0stShell
      16 Sept 2020, 12:36

      Hey,

      I try to get the raw Bytes from pictre from a QImage like

      QImage preview;
      QByteArray ba;
      QBuffer buffer(&ba);
      buffer.open(QIODevice::WriteOnly);
      qDebug() << "Saved: " << preview.save(&buffer);
      

      Yes, there is something in the QImage, I can display it.

      But save function returns a false.

      I need this to send a char array to my ESP8266 where use C so it can show the picture on an E-Paper Display

      P Offline
      P Offline
      Pl45m4
      wrote on 16 Sept 2020, 13:04 last edited by Pl45m4
      #2

      @Gh0stShell said in QImage to byte array doesn't work:

      qDebug() << "Saved: " << preview.save(&buffer);

      Have you tried using a file extension / an image format?
      preview.save(&buffer, "JPEG"); or "PNG"

      Does buffer.open(....) return true?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • G Gh0stShell
        16 Sept 2020, 12:36

        Hey,

        I try to get the raw Bytes from pictre from a QImage like

        QImage preview;
        QByteArray ba;
        QBuffer buffer(&ba);
        buffer.open(QIODevice::WriteOnly);
        qDebug() << "Saved: " << preview.save(&buffer);
        

        Yes, there is something in the QImage, I can display it.

        But save function returns a false.

        I need this to send a char array to my ESP8266 where use C so it can show the picture on an E-Paper Display

        J Offline
        J Offline
        JonB
        wrote on 16 Sept 2020, 13:15 last edited by
        #3

        @Gh0stShell
        Since the example for this at https://doc.qt.io/qt-5/qimage.html#save-1 shows

        image.save(&buffer, "PNG"); // writes image into ba in PNG format
        

        I presume as @Pl45m4 says you must specify the desired format to save in since you are not using a filename with a suffix.

        1 Reply Last reply
        1
        • G Offline
          G Offline
          Gh0stShell
          wrote on 16 Sept 2020, 13:31 last edited by Gh0stShell
          #4

          When I do this, my programm is unexpectedly finishing

          I am thinking about to read the picture pixel by pixel and then convert the int to char

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bonnie
            wrote on 16 Sept 2020, 13:41 last edited by Bonnie
            #5

            QImage::save() doesn't get the raw bytes of the image, it converts the image to a file format.
            If you really want the raw bytes, do something like

            QByteArray ba((const char *)preview.constBits(), preview.byteCount());
            
            1 Reply Last reply
            6

            5/5

            16 Sept 2020, 13:41

            • Login

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