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, which format to use
QtWS25 Last Chance

QImage, which format to use

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.9k Views
  • 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.
  • F Offline
    F Offline
    Fafner
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Fafner
        wrote on last edited by
        #3

        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:)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

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