PDA

View Full Version : QImage to QString



navi1084
6th October 2008, 15:19
Hi,
I need to convert the QImage to QString and vise versa. before converting i need to compress the data. to compress i am using qcompress() and returns QByteArray.
qcompress() successfully returns compressed byteArray . But when i convert byteArray to QString , the string will be always empty. This may be because QByteArray object contain null character. How can i convert QByteArray to QString????
I used
QImage curImage("c:/file");
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
curImage.save(&buffer, "BMP");
QByteArray arr = qCompress(buffer.buffer(),5);
QString str = QString(arr);

when i use last statement str will be null... but arr will have contents....

caduel
6th October 2008, 15:27
try QByteArray::toBase64()


QString str = arr.toBase64();

navi1084
7th October 2008, 08:29
Thank you... its working fine... when i convert QString to QByteArray by means of fromHex(), it converts to QByteArray.
But when i save the image using the contents of QbyteArray, it will be black. Image maintains the dimensions , but saved image will be black..

Can anyone tell me how can i convert it to proper format???