PDA

View Full Version : Creating a Pixmap out of an array of data



toratora
5th June 2007, 19:39
Hi

I have my picture data on an array (unsigned char array, three chars per pixel) and I want to create a Pixmap to display it. How can I do that?

On the other hand, what's the fastest way to display bitmaps? Cause I'm using QLabel now, but I don't think that's the better way.

Thanks

marcel
5th June 2007, 19:50
Use QPixmap::loadFromData( const uchar*, ... ).

As for the fastest way, that depends on what you need to do.
If you display only one image at a time, then QLabe is OK.
If you have more images, then you should switch to QGraphicsView.

Regards

toratora
5th June 2007, 20:00
Thanks!

I tried that method but I get a valid Pixmap but without the right info. I just get a black picture. Do I have to specify any format?
Just to let you know, that what I have:

on header file:
unsigned char rgbdata[352 * 288 * 3];
QPixmap pixmap;
...

on constructor:
pixmap = QPixmap(width,height);
...
to display, after getting the data:
if(pixmap.loadFromData(rgbdata,352*288*3))
pixmap.save("test.jpg");



Thanks!