PDA

View Full Version : Creating images from sets of data.



maverick_pol
25th February 2008, 14:42
Hi,

I am looking for a method to port MFC code to QT;

This is the MFC code:


short int tab = { 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF };
CBitmap* bitmap;
bitmap -> CreateBitmap(8, 8, 1, 1, tab);


I need to create a QBrush from that bitmap.

Thanks for help.

Kacper

ChristianEhrlicher
25th February 2008, 14:44
See QImage ctor (http://doc.trolltech.com/4.3/qimage.html#QImage-5)

maverick_pol
25th February 2008, 14:53
Thanks.

Can we cast short int -> uchar* without any error?

wysota
25th February 2008, 14:57
uchar is 8b long whereas short int is 16b on 32b machines. Might be different on others, but I suggest you try and see for yourself.

maverick_pol
26th February 2008, 09:00
Ok. Thanks all for help.
Here's the final code I have:


/*! Some data*/
QByteArray array;
array.resize(18);
array[0] =0x0089;
array[1] =0x0044;
array[2] =0x0010;
array[3] =0x0022;
array[4] =0x0094;
array[5] =0x0002;
array[6] =0x0068;
array[7] =0x0001;

QImage image(QSize(8,8),QImage::Format_MonoLSB);
image.loadFromData(array);


Now, though, I would like to convert this image: change black pixels -> transparent background, change white-like element to the selected colour.
If you have any idea I would appreciate your help.

Kacper

maverick_pol
26th February 2008, 09:25
Got the answer:


qDebug()<<image.colorTable().size();/*!< "2" -> white & black */
image.setColor(0,Qt::transparent);/*!< Black -> transparent*/
image.setColor(1,qRgb(255,0,0));/*!< White-> red*/


Sorry for bothering you.

Kacper