PDA

View Full Version : Bitmap to byte array



Otherside
14th January 2012, 16:21
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

wysota
14th January 2012, 16:32
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.

Otherside
15th January 2012, 01:35
Thx for the reply.

At the moment I have problem with getting RGB values.


...
QImage image(fileName);
image = image.convertToFormat(QImage::Format_RGB32);
...
for (int j = 0; j < 640; j++ ){
QRgb tempColorRgb = bitmap.pixel(QPoint(j,row));
QColor tempColor(tempColorRgb);
buffer[j] = (tempColor.red() & 0xE0>> 16) | (tempColor.green() & 0xE0 >> 8) | tempColor.blue() & (0xC0 >> 6);
}

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?

Otherside
15th January 2012, 10:26
There is error in above code, should be:

buffer[j] = (tempColor.red() & 0xE0) | (tempColor.green() & 0xE0 >> 3) | tempColor.blue() & (0xC0 >> 6);
but it dosen't change much.

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

wysota
15th January 2012, 11:33
There is error in above code, should be:

buffer[j] = (tempColor.red() & 0xE0) | (tempColor.green() & 0xE0 >> 3) | tempColor.blue() & (0xC0 >> 6);
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.

Otherside
15th January 2012, 15:03
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):
7272
7271
Any clues?

Otherside
15th January 2012, 21:17
Solved. Problem was somewhere else...