PDA

View Full Version : color table with QGradient and QImage



desch
22nd May 2008, 09:26
Hello all,

I try to make a classic color scale using two colors; the aim is to enter the color start and the color end and the QLinearGradient will calculate all colours for me ; So I can get it using QImage::colorTable();

I didn't succeed so I send you a piece of my code:


QColor start = Qt::red;
QColor stop = Qt::green;


QLinearGradient linearGrad(QPointF(100,100), QPointF(200, 200));
linearGrad.setColorAt(0, start);
linearGrad.setColorAt(1, stop);

// create image and fill it with gradient
QImage image(100, 100, QImage::Format_ARGB32);
QPainter painter(&image);
painter.fillRect(image.rect(),linearGrad);

// get all colors from the table
QVector<QRgb> tmpColorVec = image.colorTable();
qDebug(QString::number(tmpColorVec.count()).toAsci i());

for (int i = 0 ; i < tmpColorVec.count(); ++i)
{
QRgb color = tmpColorVec.at(i);
qDebug("R = " + QString::number(qRed(color)).toAscii() +
" G = " + QString::number(qGreen(color)).toAscii() +
" B = " + QString::number(qBlue(color)).toAscii());
}



Questions : What I do wrong?
What should I do?

Thanks to all

David

wysota
22nd May 2008, 10:06
The colour table is only available in 8 bit (or less) images. There is no concept of colour table for 24+ deep images. I explained it about a week ago in some other thread.

desch
22nd May 2008, 10:16
Ok Thanks,

But Is there a basic way to make a color scale suing QGradient and a kind of container to grab colors results ?

David

wysota
22nd May 2008, 10:32
I think it will be much quicker if you calculate the colours yourself. The transition is linear so this shouldn't pose a problem, just add a calculated step to each of the colour components.