Important: Please read the Qt Code of Conduct -

QImage from QDatastream of float values

  • 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);
    quint8 width, height;
    out >> width, height;
    int pixel= widthheight;
    float =new floatpixel;
    QByteArray buffer;
    int index=0;
    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];, “PNG”);
    delete temp;

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

  • Lifetime Qt Champion

    Hi and welcome to devnet,

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

  • @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.

  • Lifetime Qt Champion

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

Log in to reply