PDA

View Full Version : QByteArray into QPixmap



yagabey
12th February 2008, 14:36
Hello friends,

I am getting an image into a databuffer and after I want to display it on screen. I did something like that:

Here I put the image into databuffer...
code:


for(i=1; i<=packNum ;i++) {
Get_Image_Data(dataBuffer,512,&rec);//I read 512 bytes size per package from the port..
arr.append(dataBuffer);
}



Here I display the image on screen...
code:


QPixmap image = new QPixmap();
image->loadFromData(arr.data());
label->setPixmap(*image);



I see in the log that as data comes continuously(like video ), size of the "arr" changes. I mean , something really fills "arr"... But nothing is displayed on the screen... Any idea ..? Thanks....

jpn
12th February 2008, 17:12
I am getting an image into a databuffer
What image format?

PS. It's unnecessary to allocate QPixmap on the heap, it's an implicitly shared class.

marcel
12th February 2008, 17:16
If it is in an unusual format then you could create a QImage and set its pixels with QImage::setPixel. Note that you should set the image's size before ever calling setPixel.

pherthyl
12th February 2008, 19:15
Except don't use setpixel, as it is very slow. Use bits() directly. More information here: http://www.qtcentre.org/forum/f-qt-programming-2/t-qimage-data-via-ffmpeg-9935.html

yagabey
12th February 2008, 21:28
The format of the image is jpeg, I also tried to set image size before; but this time a white screen is displayed instead....

Sorry, what's "allocating on the heap" ?

And actually i made it work by using a QDatastream and a QImage(i put the jpeg stream in a temp file then displayed )... But it was slow...

By the way, thanks for your replies...i ask for more... :)

marcel
12th February 2008, 21:31
The format of the image is jpeg, I also tried to set image size before; but this time a white screen is displayed instead....

Not what format is the original file, but the decoded data. Is it RGB, ARGB, YUV, etc? Knowing this, you will know how to set the pixel data in the image/pixmap.

yagabey
12th February 2008, 21:59
I am getting the images from a camera. In the datasheet it says that:

" The OV528 takes 8-bit YCbCr 422 progressive video data from an OV7640/8 CameraChip. The camera interface synchronizes with input video data and performs down sampling, clamping and windowing functions with desired resolution, as well as color conversion that is requested by the user through serial bus host commands."

Is that the answer: YCbCr ?

marcel
12th February 2008, 22:04
Then you need to convert the data that comes from the camera from YCbCr to RGB. You have to do this before or while constructing the QImage.
Here's something to get you started: http://en.wikipedia.org/wiki/YCbCr. (http://en.wikipedia.org/wiki/YCbCr)
This article shows you how to convert the data to RGB.

yagabey
12th February 2008, 22:05
Ok thanks, i ll check it..

yagabey
12th February 2008, 22:13
Something sticked in my mind..
Isnt that YCbCr or RGB , a matter of color. If that was the problem, shouldn't i see something on the screen ( perhaps with distorted colors). But i see nothing...

marcel
12th February 2008, 22:19
Yes, because you're not constructing the image correctly yet. You can do it as pherthyl suggested in his post.

Don't think, just do it!