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();
qDebug() << "OUT IMAGE FORMAT HAS ALPHA CHANNEL " << outImage.hasAlphaChannel();
To copy to clipboard, switch view to plain text mode
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
));
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));
To copy to clipboard, switch view to plain text mode
With the above nothing happens. If I use:
outImage.setPixel(x,y, (uint) qRgba(255,255,255,255));
outImage.setPixel(x,y, (uint) qRgba(255,255,255,255));
To copy to clipboard, switch view to plain text mode
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));
outImage.setPixel(x,y, (uint) qRgba(255,255,255,100));
To copy to clipboard, switch view to plain text mode
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)) ;
outImage.setPixel(x,y, (uint) qRgba(0, 0, 0, 0)) ;
To copy to clipboard, switch view to plain text mode
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.
Bookmarks