Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[solved]Alpha composition in a QGraphicsScene with two overlayed QPixmap
I have a main window with 2 QGraphicsScene, each containing 2 QPixmap.
For both QGraphicsScene, the first QPixmap is a greyscale image.
And the second one (drawn on top) is a color ARGB image with transparency.
If the ARGB image has binary transparency (0 or 255) the rendering is exactly what I expect.
But if this image has semi transparent pixel, then the composition is a total mess.
"Correct (binary transparency)":http://pix.wefrag.com/i/a/d/2/d/f/44739f9da96542a083a794ed2eff5531.png :
"Overlay renderered on white":http://pix.wefrag.com/i/9/d/6/e/e/44741efd1dd259bfbd164bb8f92c6b34.png
What am I forgetting?
Thanks a lot for your help!
dangelog last edited by
How are you drawing the two pixmaps? Can you paste the two images as well as a testcase?
My first suspect in such a case are roundoff errors, but it's impossible to say without seeing some code.
Thanks for your answer.
I first fill a 4 channel uchar buffer that I convert to a QImage with: @QImage image(buffer, imgW, imgH, 4*imgW, QImage::Format_ARGB32_Premultiplied);@ I tried to save a png @image.save("overlay2.png");@ but when I open it with photoshop:
- the background is transparent
- the colored pixels are not (just like if they had been merged with a white background)
I have the feeling that my alpha are not correct, but can I trust that png to debug my code?
I fixed a few mistakes, but I still have one big issue:
- pixels with alpha=0 are transparent
- pixels with alpha=255 show a correct color
- pixels with alpha€[1-254] have a correct transparency but they are gray!!??
EDIT: fixed by removing the premultiplied flag. If you had not asked for my images, I'm not sure I had searched bugs in this place!