PDA

View Full Version : QT 5 QImage alpha value not updating



UKCitizen1423
17th May 2015, 23:17
Hi All,

I want to change the alpha value for all pixels which are black on an image and hitting some real hassles with this. The solutions out there do not work for me. I load a jpg then convert the image using QImage::Format_ARGB32


qDebug() << "OUT IMAGE FORMAT HAS ALPHA CHANNEL " << outImage.hasAlphaChannel();

The above shows as true. I then try:


for (int y = 0; y < outImage.height(); y++) {
for (int x = 0; x < outImage.width(); x++) {
QColor c = outImage.pixel(x, y);
outImage.setPixel(x,y, (uint) qRgba((int) c.red(), (int) c.green(), (int) c.blue(), 0)) ;
}
}
mainIm->setPixmap(QPixmap::fromImage(outImage));


With the above nothing happens. If I use:


outImage.setPixel(x,y, (uint) qRgba(255,255,255,255));


I see a perfect solid white square that replaces the image. As expected.

If I use:


outImage.setPixel(x,y, (uint) qRgba(255,255,255,100));


I see the original image with transparent white square at opacity 100;

If I use:


outImage.setPixel(x,y, (uint) qRgba(0, 0, 0, 0)) ;


Nothing happens.

I've tried so many variations based on the solutions here on SO and QT forums my head now hurts so I need to ask for help :-( I was expecting to use in combination with scanline for performance but not too important with respect to speed.

All help appreciated.

Thanks.