PDA

View Full Version : [SOLVED]Image color Convert, stumbling upon answer



2lights
27th August 2013, 07:43
[Solved]
Changed from QLabel to QGraphicsView


QGraphicsColorizeEffect *effect;
effect = new QGraphicsColorizeEffect;

effect->setColor(QColor(Qt::red));


Apologies for any inconvenience
Next time will do my homework better before posting

Apologies

Kind Regards


-----------------------------------------------------------------------------------------------------------------------------


This is a similar thread to others, but not the same!

I was initially trying to convert an image to gray scale
when my code instead of converting everything to grayscale
took a black & white image kept the black as is & converted the the white to dark blue----> fantastic

Thats actually what i needed, the thing is how do I change what colour should the white be converted to?
because technically my code does not specify blue!



image1 = image1.convertToFormat(QImage::Format_RGB32);

QRgb color;
for (int i=0; f1<image1.width(); i++) {
for (int j=0; j<image1.height(); j++) {
color = image1.pixel(i, j);
image1.setPixel(i, j, QColor((qRed(color) + qGreen(color) + qBlue(color))/3).rgb());
}
}


Whenever i put the above code i my program it converts all white to blue :confused:

Initially i wanted grayscale but im more than happy with this result
though I want to choose which color

Ideas please


Kind Regards

wysota
27th August 2013, 07:48
How is the code you posted related to what you have written in the description?

mergele
27th August 2013, 07:50
I just started with Qt, but shouldn't line 4 be:

for (int i=0; i < image1.width(); i++)

2lights
27th August 2013, 08:18
[Solved]
Changed from QLabel to QGraphicsView



QGraphicsColorizeEffect *effect;
effect = new QGraphicsColorizeEffect;

effect->setColor(QColor(Qt::red));


Apologies for any inconvenience
Next time will do my homework better before posting

Kind Regards:)

wysota
27th August 2013, 08:34
You can apply the colorize effect to the label as well.