PDA

View Full Version : problem with Recieving grayscale



navi1084
24th September 2008, 14:22
Hi,
My program is designed to receive a gray scale image from external media. My media is sending a proper gray scale image byte by byte. But while receiving in my program Qt will convert it to 8 bit color. That is, i am using following function to receive it.
QImage image = QImage((uchar*)DataValues.data(), 300, 300, QImage::Format_Indexed8);

Here Datavalues is of type QByteArray.

Can any one please tell me how can i receive the gray image as grayed itself.???


Thank You

jacek
27th September 2008, 22:51
The docs say:
Constructs an image with the given width, height and format, that uses an existing memory buffer, data. The width and height must be specified in pixels, data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.
The buffer must remain valid throughout the life of the QImage. The image does not delete the buffer at destruction.
If format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with setNumColors() or setColorTable() before the image is used.
With 300x300 image you fulfill the alignment requirements, but still you have to make sure that DataValues exists long enough and you have to set the color table.