PDA

View Full Version : change pixmap color, clip background



Bocky
9th November 2013, 14:08
hi

i have a pixmap from a png picture
now i want to paint all pixels of this pixmap more red or blue for example, but ignore the background
i tried to createmaskfromcolor function but it doesnt work.

with setting the opacity i get the desired effect but the white background is also drawn in red.


QColor color;
QPixmap input=*CurrObject->getImage(TypeValues[ComboBoxType->currentIndex()]);
QImage image(input.size(), QImage::Format_ARGB32_Premultiplied);
color=Qt::red;
image.fill(color);
QPainter p(&image);
p.setOpacity(0.5);
p.drawPixmap(0,0,input);
p.end();
QPixmap output = QPixmap::fromImage(image);
ui->Label2D->setPixmap(output);

Bocky
9th November 2013, 18:31
got it!
just had to add
output.setMask(input.mask()); at the end