Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QImage from QDatastream of float values

    C++ Gurus
    2
    4
    607
    Loading More Posts
    • 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.
    • connecting_dots
      connecting_dots last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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

        connecting_dots 1 Reply Last reply Reply Quote 2
        • connecting_dots
          connecting_dots @SGaist last edited by

          @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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • First post
              Last post