My program generate 3 different images and I'd like to combine them using some opacity settings.
我的程序生成3个不同的图像,我想使用一些不透明度设置组合它们。
First I have the raw image, which I already converted into a QPixmap to display it in a QGraphicsView.
首先我有原始图像,我已经将其转换为QPixmap以在QGraphicsView中显示它。
.
。
Then with this image I make some calculation and generate a QImage because I need basic pixel access, I also add a legend.
然后使用此图像我进行一些计算并生成QImage,因为我需要基本像素访问,我还添加了一个图例。
.
。
What I'd like to do is to be able to blend the two images while being able to modify the opacity. I don't have the tools to show an example, it should look like this:
我想做的是能够混合两个图像,同时能够修改不透明度。我没有显示示例的工具,它应该如下所示:
But with the first image and the data image blended with opacity. Also I'd like the legend to stay 100% visible. I can create a different QImage for the legend if it's needed.
但是第一张图像和数据图像混合了不透明度。此外,我希望这个传奇保持100%可见。如果需要,我可以为图例创建不同的QImage。
Also I know exactly which pixel should be considered transparent instead of white if it comes to that.
此外,我确切地知道哪个像素应该被认为是透明的而不是白色的。
In the future I would like to adjust the opacity just with a slider so I think it would be better if there was a solution that didn't involve calculating a whole new image every-time...
在未来我想用滑块调整不透明度,所以我认为如果有一个解决方案不涉及每次计算一个全新的图像会更好...
Any lead would be appreciated...
任何领导将不胜感激......
2 个解决方案
#1
3
You could use QGraphicsPixmapItem::setOpacity to set the alpha blend value in the range 0.0...1.0 for the overlay image and have separate graphics items for the background an the foreground.
您可以使用QGraphicsPixmapItem :: setOpacity为覆盖图像设置0.0 ... 1.0范围内的alpha混合值,并为背景和前景设置单独的图形项。
If you actually need to generate a pixmap with the blended image, you can use setOpacity on QPainter before drawing the pixmap on it.
如果您确实需要使用混合图像生成像素图,则可以在QPainter上使用setOpacity,然后在其上绘制像素图。
#2
0
There is a QImage type that supports an alpha channel QImage::Format_ARGB32_Premultiplied which will display the two images with an opacity controlled by the alpha - simply draw the two QImages over the top of each other
有一个QImage类型支持alpha通道QImage :: Format_ARGB32_Premultiplied,它将显示由alpha控制的不透明度的两个图像 - 只需将两个QImages绘制在彼此的顶部
But it is premultiplied so you need to adjust all the pixels if you change A
但它是预乘的,因此如果更改A,则需要调整所有像素
#1
3
You could use QGraphicsPixmapItem::setOpacity to set the alpha blend value in the range 0.0...1.0 for the overlay image and have separate graphics items for the background an the foreground.
您可以使用QGraphicsPixmapItem :: setOpacity为覆盖图像设置0.0 ... 1.0范围内的alpha混合值,并为背景和前景设置单独的图形项。
If you actually need to generate a pixmap with the blended image, you can use setOpacity on QPainter before drawing the pixmap on it.
如果您确实需要使用混合图像生成像素图,则可以在QPainter上使用setOpacity,然后在其上绘制像素图。
#2
0
There is a QImage type that supports an alpha channel QImage::Format_ARGB32_Premultiplied which will display the two images with an opacity controlled by the alpha - simply draw the two QImages over the top of each other
有一个QImage类型支持alpha通道QImage :: Format_ARGB32_Premultiplied,它将显示由alpha控制的不透明度的两个图像 - 只需将两个QImages绘制在彼此的顶部
But it is premultiplied so you need to adjust all the pixels if you change A
但它是预乘的,因此如果更改A,则需要调整所有像素