Results 1 to 7 of 7

Thread: Loading a raw image into QImage

  1. #1
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Loading a raw image into QImage

    Hi! I'm trying to read data pointed by unsigned char* in RG565 in QImage. I found something on the forums, and I wrote this... but the result is not the image...

    Qt Code:
    1. QImage* rawImage = new QImage(QSize(_width, _height), QImage::Format_RGB16);
    2. for (int i = 0; i < 256; i++) rawImage->setColor(i, qRgb(i, i, i));
    3. for (int i = 0; i < _height; i++) {
    4. unsigned char* image = rawImage->scanLine(i);
    5. for (int j = 0; j < _width*2; j++) image[j] = data[i*_width*2 + j];
    6. }
    7. rawImage->save("path");
    To copy to clipboard, switch view to plain text mode 

    Any idea what could be wrong?
    Thanks!

  2. #2
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Loading a raw image into QImage

    Did you try QImage::fromData ?

  3. #3
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Loading a raw image into QImage

    No, because fromData requires a format for the image. Raw is not a supported format as far as I know.

  4. #4
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Loading a raw image into QImage

    Sorry for fromData. It is not, what you need. Did you try constructor QImage::QImage ( const uchar * data, int width, int height, Format format ) like this:
    Qt Code:
    1. QImage rawImage( data, _width, _height, QImage::Format_RGB16 );
    To copy to clipboard, switch view to plain text mode 
    if it wouldn't work, try to change your code like this:
    Qt Code:
    1. unsigned short* usData = (unsigned short*)data;
    2. for (int i = 0; i < _height; i++)
    3. {
    4. unsigned short* image = (unsigned short*)rawImage->scanLine(i);
    5. for (int j = 0; j < _width; j++)
    6. image[j] = usData[i*_width + j];
    7. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Loading a raw image into QImage

    I get always the same result... I'm beginning to suspect the data has something wrong...
    Thanks for your help!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Loading a raw image into QImage

    Do you get complete garbage or do you see any shapes in the image or how does it look like? I don't know anything about RGB565 - does it store colours in a lookup table and "pixel data" represents indexes in the lookup table or do the "pixel data" contain actual colours? Because your first piece of code tries to setup the lookup table but then I don't see what the 5-6-5 combination would represent. I would rather expect it to contain actual colour data.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Loading a raw image into QImage

    I found some information about how to do that in some forums and so I tried many ways to make it work. In some they created that table, but I couldn't understand why. The result is a uniformly green image, even with this instruction suggested :

    Qt Code:
    1. QImage rawImage( data, _width, _height, QImage::Format_RGB16 );
    To copy to clipboard, switch view to plain text mode 

    As far as I know RGB565 stores 16 bits pixels one after the other with 5 bits for red, 6 bits for green and 5 bits for blue. I thought I could just copy all the data byte by byte in the QImage, but it seems the result is always the same...

Similar Threads

  1. Loading corrupt jpeg images with QImage
    By mikeee7 in forum Qt Programming
    Replies: 15
    Last Post: 3rd December 2010, 02:59
  2. Loading an image into memory
    By Luc4 in forum Qt Programming
    Replies: 6
    Last Post: 12th April 2010, 09:44
  3. problems loading an image .jpg
    By maider in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2009, 12:57
  4. Image Loading
    By kavinsiva in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2009, 09:00
  5. QImage not loading successively.
    By node_ex in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2008, 14:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.