Results 1 to 11 of 11

Thread: QByteArray into QPixmap

  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default QByteArray into QPixmap

    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:

    Qt Code:
    1. for(i=1; i<=packNum ;i++) {
    2. Get_Image_Data(dataBuffer,512,&rec);//I read 512 bytes size per package from the port..
    3. arr.append(dataBuffer);
    4. }
    To copy to clipboard, switch view to plain text mode 



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

    Qt Code:
    1. QPixmap image = new QPixmap();
    2. image->loadFromData(arr.data());
    3. label->setPixmap(*image);
    To copy to clipboard, switch view to plain text mode 


    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....

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QByteArray into QPixmap

    Quote Originally Posted by yagabey View Post
    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.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray into QPixmap

    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.

  4. #4
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QByteArray into QPixmap

    Except don't use setpixel, as it is very slow. Use bits() directly. More information here: http://www.qtcentre.org/forum/f-qt-p...mpeg-9935.html

  5. #5
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QByteArray into QPixmap

    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...

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray into QPixmap

    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.

  7. #7
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QByteArray into QPixmap

    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 ?

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray into QPixmap

    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.
    This article shows you how to convert the data to RGB.

  9. #9
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QByteArray into QPixmap

    Ok thanks, i ll check it..

  10. #10
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QByteArray into QPixmap

    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...

  11. #11
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray into QPixmap

    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!

  12. The following user says thank you to marcel for this useful post:

    yagabey (12th February 2008)

Similar Threads

  1. Convert QPixmap to QByteArray ?
    By probine in forum Qt Programming
    Replies: 5
    Last Post: 13th March 2014, 09:23
  2. QPixmap bug under Qt4.3.1 ?
    By Nyphel in forum Qt Programming
    Replies: 8
    Last Post: 7th October 2007, 18:04
  3. QPixmap from QByteArray.
    By munna in forum Qt Programming
    Replies: 6
    Last Post: 8th July 2006, 16:37
  4. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 17:24
  5. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 18:01

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.