简体   繁体   中英

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.

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:

圆圈上没有透明度的白色背景

The same circle with 50% opacity on white background:

在此处输入图像描述

The circle with transparency on a grid background:

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM