Results 1 to 3 of 3

Thread: reading in image from 24bit char*

  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

  2. #2
    Join Date
    Jan 2006
    Location
    N.B. Canada
    Posts
    47
    Thanked 8 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: reading in image from 24bit char*

    Just so you are aware, QImage supports only 1, 8, and 32 bit formats. So AFAIK, your only option is to do it manually.

    Bojan
    The march of progress:
    C:
    printf("%10.2f", x);
    C++:
    cout << setw(10) << setprecision(2) << showpoint << x;
    Java:
    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(2);
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(x);
    for (int i = s.length(); i < 10; i++) System.out.print(' ');
    System.out.print(s);

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

    Default Re: reading in image from 24bit char*

    Yes, I'm aware QImage only supports those types. I just thought that since there is a method to read in 24bit images from files, there might be a similar one for reading directly from data arrays. In any case, the manual method seems to be working well.

    I need to display multiple image streams (that may be started or stopped at any time). Would it be a bad idea to write these pixmaps onto icons in an iconview?

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