Sorry, yes, localpixels().
Looking at this http://doc.qt.io/qt-4.8/qimage.html it seems that for the
QImage constructor I used as an example, it doesn't COPY the data, but rather
just points to it, to it's crucial that the ImageBuf survive for the entire
lifetime of the QImage. I'm sure that's your problem -- by letting the ImageBuf
get destroyed when it leaves scope but returning the QImage that inadvertently
points to the ImageBuf's (now invalid) memory, you would expect chaos.
I think, then, that instead you want something like:
QImage *newQImage = new QImage (myImageBuf.spec().width,
myImageBuf.spec().height,
QImage::Format_RGB888);
// now your QImage owns its own memory
And, ick, I think you would need to copy things in scanline by scanline?
Something like
for (int i = 0; i < height; ++i)
myImageBuf.get_pixels (ROI(0,width,line,line+1,0,1,0,3/*nchannels*/),
TypeDesc::UINT8,
newQImage->scanline(i));
Maybe there's something in QImage that I'm missing that would let you do it in
one step. I'm not sure.
> On Feb 5, 2016, at 12:16 AM, Renaud <[email protected]> wrote:
>
>> // Now create a QImage that copies the pixels from B.
>> QImage Q ((const unsigned char *)B.localdata(),
>> B.spec().width, B.spec().height,
>> QImage::Format_RGB888);
>>
>
> Hi Larry !
> I apologize for the delayed answer, I didn't get any notification from the
> mailing list so I assumed nobody answered my message. Thank you very much
> again for the help. I think an example which goes all the way to a QImage
> would be great in the doc.
> When I read the documentation I had a hard time figuring out where the image
> "raw data" was "stored" when using an ImageBuf reading method.
> "localdata()" from your example seems to be what I was missing but
> unfortunately it doesn't seem to exist.
>
> I replaced "B.localdata()" with "B.localpixels()", the code compiles but the
> program crashes when I try to display the resulted QImage (most likely
> "corrupted" data). Maybe using localpixels() is the issue ?
>
> I also tried Pete's methods with no luck.
>
>
> Code:
>
> ImageBuf myImageBuf (filename);
>
> myImageBuf.read (0 /*subimage*/, 0 , true , TypeDesc::UINT8);
>
> QImage *newQImage = new QImage((const unsigned char
> *)myImageBuf.localpixels(), myImageBuf.spec().width,
> myImageBuf.spec().height, QImage::Format_RGB888);
>
> return newQImage;
>
>
> _______________________________________________
> Oiio-dev mailing list
> [email protected]
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
--
Larry Gritz
[email protected]
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org