PDA

View Full Version : How to construct Image from Bytes



vishal.chauhan
25th January 2007, 08:36
Hi All,

I m using Qt 4.2.2 on my MAC Intel.
Eariler I m using qt 3.3 in which I stored bytes in QBytes Array as-

unsigned long SizeToRead=ThumbnailSize+512;
unsigned long BytesToIgnore=TStart%512;
QByteArray qBuffer(SizeToRead-BytesToIgnore);

But when I m using this in Qt 4.2.2 it is giving the error that
Invalid Conversion from Long Unsigned Int to const char*.

Now I m using this.....

QByteArray qBuffer;
memset(&qBuffer,0x00,(SizeToRead-BytesToIgnore));

and also copy the bytes in qBuffer.

In Qt 3.3 I m using
QImage image(qBuffer) to construct image from the Bytes but when I m using this in QT 4.2.2 it is giving the following Error that..

Call of overloaded QImage(QByteArray&) is ambiguous.

Plz help me How I stored the bytes and construct the image from that.

thanks.

e8johan
25th January 2007, 09:12
I do this aswell, but I had to put a QImageReader in between:



QByteArray array = qry.value(0).toByteArray();
QBuffer buffer(&array);
buffer.open( QIODevice::ReadOnly );

QImageReader reader(&buffer, "PNG");
QImage image = reader.read();


The code did not work unless I opened the buffer explicitly, so don't forget that.

vishal.chauhan
29th January 2007, 06:41
I do this aswell, but I had to put a QImageReader in between:



QByteArray array = qry.value(0).toByteArray();
QBuffer buffer(&array);
buffer.open( QIODevice::ReadOnly );

QImageReader reader(&buffer, "PNG");
QImage image = reader.read();


The code did not work unless I opened the buffer explicitly, so don't forget that.


Thanks for Reply.
But What is qry?and how to open buffer explicitly.
Also Is QImageReader reader(&buffer, "PNG") used to constuct a PNG Image or what?
If yes then If I donot know what type of Image is this then What Will I do?