PDA

View Full Version : setGamma/setQuality to QImage



ArmanS
3rd October 2009, 02:56
Hi All,

I'm need toset/get gamma and quality/compression to/from QImage. There is very little documented about it. What I've been able to do so far is the following (e.g. for Quality):



int getImageQuality(const QImage &image)
{
Q_ASSERT( !image.isNull() );
QByteArray byteArray;
QBuffer buf(&byteArray);
buf.open(QIODevice::WriteOnly);
QImage imageTemp(image);
if (imageTemp.save(&buf, "PNG")) {
QImageReader reader(&buf);
return reader.quality(); // IT REACHES HERE. BUT ALWAYS RETURNS -1
}
return -1;
}

void setQuality(int Q) // MY TEST VALUE IS 50
{
QByteArray ba;
QBuffer buf(&ba);
buf.open(QBuffer::ReadWrite);
QImageWriter writer(&buf, "PNG");
writer.setQuality( Q ); // SETTING A TEST VALUE 50
bool ok = writer.write( myImage() );
Q_ASSERT( ok );
if (ok) {
QImage img;
ok = img.loadFromData(ba, "PNG");
Q_ASSERT( ok );
if (ok) {
qDebug("Quality = %d", getImageQuality(img)); // ALWAYS RETURNS -1
}
}
}

SO, but it's not working. as if no effect.
Can you please help me with this?

Thanks in advance!!

wysota
3rd October 2009, 11:00
PNG is a loseless format, it doesn't support changing the quality.