QImage, which format to use

  • Hello,

    I'm trying to create a QImage from a uchar array, and I'm not sure what format to use. I tried using Format_RGB32, but the image wasn't created at all. I then tried Format_RGB16, which created an image, but not at all correct. I know that the data in the array is correct. The code for writing the image is like this:

    QImage img(world->pixel_data, world->vp.h_res, world->vp.v_res, world->vp.h_res*3, QImage::Format_RGB16);
    QString adr = QFileDialog::getSaveFileName(this);
    img.save(adr, "PNG");

    Which format is best for rgb-data stored as uchar? I know that this question probably is a bit vague, but I'm not very familiar with this type of thing.

  • Quite vague indeed. The only one really knowing what is inside your uchar array, is you. Where does your data come from?

  • The values in the uchar array range from 0-255. I've had success now, though, using Format_RGB888. Sorry, I realize now I should have read up more before posting:)

  • Of course they do range in that range, that is a uchar's very definition. uchar arrays are often used as containers to hold arbitrairy binairy data, such as images as you found out. You need to know what is stored in the array to do anything useful with it. I am glad you found out what's in there exactly in your case.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.