Results 1 to 3 of 3

Thread: reading in image from 24bit char*

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Knoxville, TN
    Posts
    14
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default reading in image from 24bit char*

    Hi,
    I'm trying to read in an image from a character array, and I'm having some difficulties getting it into QImage and displaying it. I can write the raw data out to a file with a pgm header, and everything looks fine. So I know the data is ok.

    When I write the data out to a pgm file I see that R and B are swapped, so I'd like to make use of the RGB swapping method provided by QImage.
    The problem is that I can't read the data into a QImage. I've tried loadFromData, and I get a segfault. It seems to me that it wants to read my 24bit image stream as 32bits (I can't seem to create a 24bit image), and its running out of data at the end, of course.
    Surely there is a way to read in 24bit RGB without me having to pad each triplet with a byte for the alpha channel "manually"?
    Thanks for any advice.

    Qt Code:
    1. void MainForm::showImage( int fd, char *imgbuf ){
    2. QImage image;
    3. image.create(320,240,32); // it won't let me put 24bit depth
    4. image.loadFromData((uchar*)imgbuf, 320*240*3, 0);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Update: I've solved it for now by writing a small for loop to copy over each RGB value. Of course a built-in method would still be preferred, but it looks like it doesn't exist.
    Last edited by cbeall1; 19th February 2006 at 21:55. Reason: problem solved

Similar Threads

  1. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  2. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 15:36
  3. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  4. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53
  5. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

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.