Results 1 to 8 of 8

Thread: Problem with loading an Image from raw data

  1. #1

    Default Problem with loading an Image from raw data

    Hi everybody,

    I'm trying to load an image from raw data, which I get from a database.
    For testing purpose I saved the data to a file and wrote the code below but it won't display the image.
    I'm not that into processing images, maybe I'm missing something else.

    the raw image
    an exported version of the image

    Qt Code:
    1. QByteArray imagesData;
    2. QFile *file = new QFile(QFileDialog::getOpenFileName(this,tr("Open Image"), "", tr("")));
    3.  
    4. if(file->exists())
    5. {
    6. //get byteArray from raw data file
    7. file->open(QFile::ReadOnly);
    8. imagesData = file->readAll();
    9. file->close();
    10.  
    11. //Create qimage
    12. QImage img((const uchar*)imagesData.data(),4320,2880,QImage::Format_RGB888);
    13.  
    14. QPixmap pix;
    15. pix.fromImage(img);
    16.  
    17. ui->label->setPixmap(pix);
    18. }
    To copy to clipboard, switch view to plain text mode 

    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with loading an Image from raw data

    Well, you are setting an null pixmap on the label, so it will by definition be empty.

    You probably didn't see the "static" keyword in the signature of QPixmap::fromImage()

    Cheers,
    _

  3. #3

    Default Re: Problem with loading an Image from raw data

    I did miss that one out but it is still not working, seems like this isn't correct.

    QImage img((const uchar*)imagesData.data(),4320,2880,QImage::Format_ RGB888);

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with loading an Image from raw data

    So why aren't you simply calling QPixmap::load() or QPixmap::loadFromData() instead of going through this circuitous route of reading the data, creating a QImage and then converting that to a pixmap?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5

    Default Re: Problem with loading an Image from raw data

    What I get from the database is a raw dump without a header, so I can't use QPixmap::load() or QPixmap::loadFromData().
    The file is avaible in the first post, maybe I'm missing something again.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with loading an Image from raw data

    Are you certain that the raw dump from the database doesn't contain header information? It would seem odd to store an image as a blob but only after stripping off the header. And are you sure the image dimensions are correct? A 4320 x 2880 pixel image with one byte per color channel should be around 37 MB. The rawImage file you posted is only 4 MB.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7

    Default Re: Problem with loading an Image from raw data

    You are right, the filesize doesn't really fit and I tried to load the raw file but it didn't work.
    I really have no idear, it seems like its the jpg file without a header but as I said I'm really not into grafiks.

  8. #8
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with loading an Image from raw data

    Or ask the author of these images.

Similar Threads

  1. Image loading
    By Stanfillirenfro in forum Qt Programming
    Replies: 8
    Last Post: 15th January 2014, 14:36
  2. Loading Image
    By navi1084 in forum Qt Programming
    Replies: 2
    Last Post: 27th June 2011, 06:07
  3. image loading problem using qpixmap
    By dutt_004 in forum Qt Programming
    Replies: 4
    Last Post: 23rd February 2010, 02:18
  4. loading image from disk
    By freekill in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2010, 06:21
  5. Image Loading
    By kavinsiva in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2009, 09:00

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.