Results 1 to 7 of 7

Thread: Bitmap to byte array

  1. #1
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    2

    Question Bitmap to byte array

    Hey
    I am begginer in QT and I would like to transform bitmap file to byte array (RGB332 format).
    Any ideas how to do this?

    Regards

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

    Default Re: Bitmap to byte array

    As far as I know Qt doesn't support RGB332 natively so you'd need to do the transformation yourself and then store values into QByteArray using its API.
    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.


  3. The following user says thank you to wysota for this useful post:

    Otherside (15th January 2012)

  4. #3
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    2

    Default Re: Bitmap to byte array

    Thx for the reply.

    At the moment I have problem with getting RGB values.

    Qt Code:
    1. ...
    2. QImage image(fileName);
    3. image = image.convertToFormat(QImage::Format_RGB32);
    4. ...
    5. for (int j = 0; j < 640; j++ ){
    6. QRgb tempColorRgb = bitmap.pixel(QPoint(j,row));
    7. QColor tempColor(tempColorRgb);
    8. buffer[j] = (tempColor.red() & 0xE0>> 16) | (tempColor.green() & 0xE0 >> 8) | tempColor.blue() & (0xC0 >> 6);
    9. }
    To copy to clipboard, switch view to plain text mode 

    This should read and store to buffer one row of image. Image is opened correctly but data in buffer is not correct. For example for one color bitmap it gives almost random values (smth like 8 pixels blue then 12 black then 11 yellow etc). Diffrent images gives different results. I also tried different formats with no effect.
    What am I doing wrong?
    Last edited by Otherside; 15th January 2012 at 01:39.

  5. #4
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    2

    Default Re: Bitmap to byte array

    There is error in above code, should be:
    Qt Code:
    1. buffer[j] = (tempColor.red() & 0xE0) | (tempColor.green() & 0xE0 >> 3) | tempColor.blue() & (0xC0 >> 6);
    To copy to clipboard, switch view to plain text mode 
    but it dosen't change much.

    Why I can't edit my posts after some time?

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

    Default Re: Bitmap to byte array

    Quote Originally Posted by Otherside View Post
    There is error in above code, should be:
    Qt Code:
    1. buffer[j] = (tempColor.red() & 0xE0) | (tempColor.green() & 0xE0 >> 3) | tempColor.blue() & (0xC0 >> 6);
    To copy to clipboard, switch view to plain text mode 
    but it dosen't change much.
    You are writing 16 bits into a 32 bit memory cell. You should be writing two such data sets into one memory cell.

    Why I can't edit my posts after some time?
    Site policy for preventing data loss.
    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. The following user says thank you to wysota for this useful post:

    Otherside (15th January 2012)

  8. #6
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    2

    Default Re: Bitmap to byte array

    buffer has type unsigned char* so I think I am writing 8 bits to 8 bits?

    Anyway, here is result displayed on crt monitor and oryginal file(had to convert it to jpeg to upload here):
    IMG20120115_005.jpg
    test12345b.JPG
    Any clues?

  9. #7
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    2

    Default Re: Bitmap to byte array

    Solved. Problem was somewhere else...

Similar Threads

  1. Cast QString array to std::string array
    By Ishtar in forum Newbie
    Replies: 4
    Last Post: 15th July 2011, 08:28
  2. Replies: 2
    Last Post: 12th November 2010, 14:42
  3. PlEASE HELP: Hot To Use Byte Array, data stream
    By aash_89 in forum Qt Programming
    Replies: 7
    Last Post: 16th July 2010, 08:33
  4. declare an array of QSemaphore and array of slot functions
    By radeberger in forum Qt Programming
    Replies: 11
    Last Post: 2nd May 2010, 13:24
  5. Replies: 3
    Last Post: 19th April 2010, 14:16

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
  •  
Qt is a trademark of The Qt Company.