Results 1 to 3 of 3

Thread: get QImage object from buffer

  1. #1
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default get QImage object from buffer

    I have databuffer which is width*height*2 byte long, every pixel is two byte long(the value is the gray scale). How can I generate a QImage object from this buffer.
    It seems there is no such format in QImage.

    The following image formats are available in all versions of Qt:

    Constant Value Description
    QImage::Format_Invalid 0 The image is invalid.
    QImage::Format_Mono 1 The image is stored using 1-bit per pixel. Bytes are packed with the most significant bit (MSB) first.
    QImage::Format_MonoLSB 2 The image is stored using 1-bit per pixel. Bytes are packed with the less significant bit (LSB) first.
    QImage::Format_Indexed8 3 The image is stored using 8-bit indexes into a colormap.
    QImage::Format_RGB32 4 The image is stored using a 32-bit RGB format (0xffRRGGBB).
    QImage::Format_ARGB32 5 The image is stored using a 32-bit ARGB format (0xAARRGGBB).
    QImage::Format_ARGB32_Premultiplied 6 The image is stored using a premultiplied 32-bit ARGB format (0xAARRGGBB), i.e. the red, green, and blue channels are multiplied by the alpha component divided by 255. (If RR, GG, or BB has a higher value than the alpha channel, the results are undefined.) Certain operations (such as image composition using alpha blending) are faster using premultiplied ARGB32 than with plain ARGB32.
    QImage::Format_RGB16 7 The image is stored using a 16-bit RGB format (5-6-5).
    QImage::Format_ARGB8565_Premultiplied 8 The image is stored using a premultiplied 24-bit ARGB format (8-5-6-5).
    QImage::Format_RGB666 9 The image is stored using a 24-bit RGB format (6-6-6). The unused most significant bits is always zero.
    QImage::Format_ARGB6666_Premultiplied 10 The image is stored using a premultiplied 24-bit ARGB format (6-6-6-6).
    QImage::Format_RGB555 11 The image is stored using a 16-bit RGB format (5-5-5). The unused most significant bit is always zero.
    QImage::Format_ARGB8555_Premultiplied 12 The image is stored using a premultiplied 24-bit ARGB format (8-5-5-5).
    QImage::Format_RGB888 13 The image is stored using a 24-bit RGB format (8-8-8).
    QImage::Format_RGB444 14 The image is stored using a 16-bit RGB format (4-4-4). The unused bits are always zero.
    QImage::Format_ARGB4444_Premultiplied 15 The image is stored using a premultiplied 16-bit ARGB format (4-4-4-4).

  2. #2
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: get QImage object from buffer

    my code:

    Qt Code:
    1. //change 16 bit gray scale to 8 bit gray scale
    2. for(int i=0;i<IMAGE_WIDTH*IMAGE_HEIGHT;i++)
    3. imageBuffer[i]= (*((uint16_t *)(imageBuffer+2*i)))/4;
    4.  
    5. //get QImage object from the buffer, this might be wrong
    6. QImage image(imageBuffer,IMAGE_WIDTH,IMAGE_HEIGHT,QImage::Format_Indexed8);
    7.  
    8. //rescale the image
    9. QImage smallImg=image.scaled(600,300);
    10.  
    11. //use QLabel object to show the image
    12. labelImage->setPixmap(QPixmap::fromImage(smallImg));
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 23rd December 2008 at 21:36.

  3. #3
    Join Date
    Apr 2012
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: get QImage object from buffer

    You could also use a lookup table to encode you linear 16bit data
    Into any of your chosen format ... SetPixmap is taking so much
    Time on my embeded system at large resolution ... Any idea
    How to improve this ??

Similar Threads

  1. QImage buffer
    By rafaelsegundo in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2008, 06:48
  2. How can I save a QImage object into a SQLite3 database table?
    By danielperaza in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2008, 05:39
  3. QShared
    By sabeesh in forum Qt Programming
    Replies: 11
    Last Post: 11th October 2007, 12:40
  4. No output on frame buffer (arm target board)
    By devendra in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 29th November 2006, 20:03
  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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.