View Full Version : QImage to QByteArray

29th September 2008, 20:03
Is there any method to convert QImage to QByteArray???

Thank You

29th September 2008, 20:06
this example was taken from assistant

QImage image;
QByteArray ba;
QBuffer buffer(&ba);
image.save(&buffer, "PNG"); // writes image into ba in PNG format

29th September 2008, 20:35
Thank You..
Is there any fuction to convert QImage to uchar* . Actually i used bits(), scanline() etc. Since it returns address, i cannot manipulate the data.
Actually i need to copress the QImage row data using qCompress(). Can anyone help me out???

29th September 2008, 20:57
you can use this function

QByteArray qCompress ( const QByteArray & data, int compressionLevel = -1 )

30th September 2008, 18:21
QByteArray compressed = qCompress(QByteArray((char*)image.bits(), image.numBytes()));
QByteArray compressed = qCompress(image.bits(), image.numBytes());

15th October 2008, 10:36
i have notice to compress QByteArray is faster & smal -> http://liblzf.plan9.de/
i found this tip on KDE source...

// Lossless compression using LZF algorithm, this is faster on modern CPU than
// the original implementation in http://liblzf.plan9.de/
// compression data on cache to not fill to match ram buffer

/* search on kde source : *xml */
static int lzff_compress(const void* input, int length, void* output, int maxout)
static int lzff_decompress(const void* input, int length, void* output, int maxout)