Results 1 to 2 of 2

Thread: convert 16 bit raw data to 24bit bitmap image

  1. #1
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default convert 16 bit raw data to 24bit bitmap image

    Hi everyone,
    I have a raw data of an image(width = 127,height = 64,16 bit per pixel).I want to save and convert it into a 24 bit BMP image.For saving I am using the following code.

    Qt Code:
    1. QImage img(rawData,width,height,width * 2,QImage::Format_RGB16);
    2. img.save("test_qimg_16.bmp","BMP");
    To copy to clipboard, switch view to plain text mode 

    But the saved file was a 24bit BMP image.
    For converting i am using the following code.
    Qt Code:
    1. memcpy(buf,rawData + j,2);
    2. extract_ushort_from_buffer(buf,0,0,&num);
    3. unsigned char red = (num & 0xf800) >> 11;
    4. unsigned char green = (num & 0x07c0) >> 5;
    5. unsigned char blue = num & 0x003f;
    To copy to clipboard, switch view to plain text mode 

    The saved image is a 24bit BMP.

    But the first one is better than 2nd.
    Can any one told me when i am trying to save in 16 bit why it saved in 24 bit and how i will convert the 16bit raw data to 24 bit raw data.


    thanks.

  2. #2
    Join Date
    Aug 2011
    Posts
    44
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: convert 16 bit raw data to 24bit bitmap image

    1. Why it's saved in 24bit?
    I guess that's the answer:
    bool QBmpHandler::write(const QImage &img)
    {
    QImage image;
    switch (img.format()) {
    case QImage::Format_ARGB8565_Premultiplied:
    case QImage::Format_ARGB8555_Premultiplied:
    case QImage::Format_ARGB6666_Premultiplied:
    case QImage::Format_ARGB4444_Premultiplied:
    image = img.convertToFormat(QImage::Format_ARGB32);
    break;
    case QImage::Format_RGB16:
    case QImage::Format_RGB888:
    case QImage::Format_RGB666:
    case QImage::Format_RGB555:
    case QImage::Format_RGB444:
    image = img.convertToFormat(QImage::Format_RGB32);
    break;
    default:
    image = img;
    }
    It seems Qt's built-in code usually saves color BMP's as 32bit.

    2. How to convert?
    I guess the simple and reliable way is in using QImage::convertToFormat method:
    QImage QImage::convertToFormat ( Format format, Qt::ImageConversionFlags flags = Qt::AutoColor ) const
    QImage QImage::convertToFormat ( Format format, const QVector<QRgb> & colorTable, Qt::ImageConversionFlags flags = Qt::AutoColor ) const

Similar Threads

  1. need to convert Raw Image Data direct to QPixmap
    By syclopse in forum Qt Programming
    Replies: 6
    Last Post: 18th July 2011, 13:57
  2. How to convert JPEG image into binary data?
    By Gokulnathvc in forum Newbie
    Replies: 1
    Last Post: 7th June 2011, 08:43
  3. How to convert image data type to plain text and back ?
    By aircraftstories in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2011, 16:00
  4. Qt form to bitmap image .. How to
    By Ratheendrans in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2010, 13:22
  5. reading in image from 24bit char*
    By cbeall1 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2006, 00:09

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.