[Solved] How to create gray scale QImage(QImage::Format_Indexed) without copying memory
I'm trying to create QImage that wrap a existing image buffer that is created by OpenCv I was considering use following constructor to do this.
@QImage::QImage ( const uchar * data, int width, int height,
int bytesPerLine, Format format )@
so, my code is like
QImage qimage((const uchar*)iplImage->imageData,
QImage::Format_Indexed); // qimage's buffer is now just pointing the 'iplImage->imageData'
// without allocating and copying buffer.
qimage.setColorTable(grayScaleColorTable); // color table's item count 256 for grayscale.
// now new image buffer is allocated and copied from original here.
Ok, no memory copy actually was done at the time of calling this ctor. But, here comes my problem. QImage::setColorTables() is non const member function where QImage allocates new image buffer for copying by its internal detach() function.
I found there was Qt3 support for this kind of problem where ctor could accept color table as argument in its ctor, but I've not found any such support in > Qt4.
How can I create gray scale QImage for existing image buffer?
Thanks for in advance
I got feedback from "SO post":http://stackoverflow.com/questions/13597058/how-to-create-gray-scale-qimageqimageformat-indexed-without-copying-memory
I should have used
QImage ( uchar * data, int width, int height, Format format )
QImage ( uchar * data, int width, int height, int bytesPerLine, Format format )
QImage ( const uchar * data, int width, int height, Format format )
QImage ( const uchar * data, int width, int height, int bytesPerLine, Format format )