Results 1 to 7 of 7

Thread: QImage from uchar buffer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default QImage from uchar buffer

    I'm trying to create a QImage from a buffer, but it doesn't work. If I use setPixel() it works, but if I use a uchar buffer, the Image won't be drawn.

    Any idea why?

    Qt Code:
    1. int imwidth = 4;
    2. int imheight = 16;
    3.  
    4. uchar BUF[] = {
    5. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    6. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    7. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    8. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    9. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    10. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    11. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    12. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    13. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    14. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    15. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    16. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    17. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    18. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    19. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0,
    20. 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0
    21. };
    22.  
    23.  
    24. QImage qi(BUF, imwidth, imheight, QImage::Format_ARGB32); // doesn't work
    25. QRect s(0, 0, imwidth, imheight);
    26. painter->drawImage(s, qi, s, Qt::AutoColor);
    To copy to clipboard, switch view to plain text mode 

    http://developer.qt.nokia.com/doc/qt-4.8/qimage.html

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: QImage from uchar buffer

    First, you need to figure out whether the image it is a) not drawn or b) not created properly... I'd suggest the latter, as you have 16 x 16 bytes in your buffer, but you need 16 x 16 x 4 bytes...

Similar Threads

  1. Replies: 2
    Last Post: 19th July 2018, 06:38
  2. get QImage object from buffer
    By Sheng in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2012, 02:03
  3. QImage buffer
    By rafaelsegundo in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2008, 06:48
  4. Creating a QImage from uchar* data
    By forrestfsu in forum Qt Programming
    Replies: 6
    Last Post: 8th February 2007, 15:21
  5. QImage from 8 bit char* RGB buffer
    By tboloo in forum Qt Programming
    Replies: 13
    Last Post: 15th April 2006, 19:56

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
  •  
Qt is a trademark of The Qt Company.