Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. QImage from QDatastream of float values
Forum Updated to NodeBB v4.3 + New Features

QImage from QDatastream of float values

Scheduled Pinned Locked Moved Unsolved C++ Gurus
4 Posts 2 Posters 879 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.
  • C Offline
    C Offline
    connecting_dots
    wrote on 8 Apr 2019, 21:29 last edited by
    #1

    Hi all,
    I am getting image through UDP. In the payload of the frame, first 1 byte is width, and second byte is height and then image float values(32x32). Using QDataStream, I am trying to generate QImage but somehow I am not getting the correct solution. I am just stuck for converting and reading the the float values.

    QDataStream out(udpdata);
    out. setByteOrder(QDataStream::LittleEndian);
    out.setFloatingPointPrecesion(QDataStream::SinglePrecision);
    quint8 width, height;
    out >> width, height;
    int pixel= widthheight;
    temp
    float =new floatpixel;
    QByteArray buffer;
    int index=0;
    out.readbytes(temp,pixel);
    buffer.append(temp, pixel);
    QImage image(width, height, QImage::Format_RGB32);
    for(int i=0; i<=(pixel-1); ++i; ++index)
    image.bits() [index] = buffer[i];
    image.save(image, “PNG”);
    delete temp;

    Also, I am getting different images from UDP, so the size of the image is not fixed every time.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Apr 2019, 21:37 last edited by
      #2

      Hi and welcome to devnet,

      QImage doesn't support floating point types. Did you convert it before sending it ?

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

      C 1 Reply Last reply 9 Apr 2019, 10:05
      2
      • S SGaist
        8 Apr 2019, 21:37

        Hi and welcome to devnet,

        QImage doesn't support floating point types. Did you convert it before sending it ?

        C Offline
        C Offline
        connecting_dots
        wrote on 9 Apr 2019, 10:05 last edited by
        #3

        @SGaist Thanks. I am trying to convert it into quint32 but still not working out for me. I guess, I am getting confused in extracting each float value from datastream. Also readRawdata and readBytes only supports char s it gives me error saying invalid conversion.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 9 Apr 2019, 20:50 last edited by
          #4

          What kind of images are that in the first place ?
          Where do they come from ?

          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

          1/4

          8 Apr 2019, 21:29

          • Login

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