PDA

View Full Version : Filling an image



Caius Aérobus
6th July 2008, 00:04
file.h:

QImage background;

file.cxx:

this->background = QImage(size, QImage::Format_RGB32);
this->background.fill(Qt::black);
std::vector<double>::const_iterator it = values.begin();
for (int j=0 ; j<this->original_size[1] ; j++)
for (int i=0 ; i<this->original_size[0] ; i++,it++)
if (*it >= 1)
for (int ii=0 ; ii<factor ; ii++)
for (int jj=0 ; jj<factor ; jj++)
this->background.setPixel(i*factor+ii, j*factor+jj, Qt::green);
int g=0, b=0;
for (int j=0 ; j<background.height() ; j++)
for (int i=0 ; i<background.width() ; i++)
if (background.pixel(i,j) == Qt::black)
b++;
else if (background.pixel(i,j) == Qt::green)
g++;
printf("%d black pixels and %d green pixels\n", b, g);


Expected result: some green pixels among black ones (I checked there really are some points for which *it == 1)
Actual result: 0 0 !

jpn
6th July 2008, 17:29
Qt::black and Qt::green are values of enum Qt::GlobalColor. The value of Qt::black is 2 and Qt::green is 8. Comparing these values to the values of image pixels doesn't make sense to me...

Caius Aérobus
6th July 2008, 18:30
Qt::black and Qt::green are values of enum Qt::GlobalColor. The value of Qt::black is 2 and Qt::green is 8. Comparing these values to the values of image pixels doesn't make sense to me...

Ok, it is no doubt for me that you are right Guru, but beyond that could you ALSO help me solving the problem?

jpn
6th July 2008, 18:41
What is

background.setPixel(i*factor+ii, j*factor+jj, Qt::green);
supposed to do? Remember that Qt::green is not an RGB value but an enum value.

Caius Aérobus
6th July 2008, 20:08
Ok, I have solved the problem, I need to explicitely give the ARGB values, ie 0xff00ff00 for green. I just believed that there was a way to get it as a constant for classic colors, as with Qt::green and so.

jpn
6th July 2008, 20:13
Ok, I have solved the problem, I need to explicitely give the ARGB values, ie 0xff00ff00 for green. I just believed that there was a way to get it as a constant for classic colors, as with Qt::green and so.
It's still an enum value. :) To get an RGB value you would do something like:


QRgb rgb = QColor(Qt::green).rgb();

Caius Aérobus
6th July 2008, 21:13
It's still an enum value. :) To get an RGB value you would do something like:


QRgb rgb = QColor(Qt::green).rgb();


Not an enum but a constant, and finally easier than the above solution lol