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.
void MainForm::showImage( int fd, char *imgbuf ){
image.create(320,240,32); // it won't let me put 24bit depth
image.loadFromData((uchar*)imgbuf, 320*240*3, 0);
}
void MainForm::showImage( int fd, char *imgbuf ){
QImage image;
image.create(320,240,32); // it won't let me put 24bit depth
image.loadFromData((uchar*)imgbuf, 320*240*3, 0);
}
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.
Bookmarks