Search code examples
c++qttransparencyqimagealpha-transparency

How to save a QImage with transparency?


I want to create a PNG image with transparency.

QImage image(dim, dim, QImage;;Format_ARGB32);

And I set the

qRgba(qRed, qGreen, qBlue, alpha)

But the alpha channel does not modify the transparency/opacity of the color, instead modify the intensity color (from white to color).

Thus, how can I set the transparency of the QImage (which I save on file)?

I have to use QImage, no other stuff.


Solution

  • How do you expect to see the transparency? Ordinary image viewers like photo viewers in Windows and Linux are painting the image on a white canvas. That's why the transparent pixels are being blended with white color. Look at the pictures below :

    White background with no transparency on the circle:

    White background with no transparency on the circle

    The same circle with 50% opacity on white background:

    enter image description here

    The circle with transparency on a grid background:

    enter image description here

    That is why advanced image editors like Photoshop, are using such canvas as their default background.