Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blending two different images in Qt

My program generate 3 different images and I'd like to combine them using some opacity settings.

First I have the raw image, which I already converted into a QPixmap to display it in a QGraphicsView.

First Image.

Then with this image I make some calculation and generate a QImage because I need basic pixel access, I also add a legend.

Second Image.

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:

Third image

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.

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...

like image 786
Leo Avatar asked Jun 20 '12 14:06

Leo


1 Answers

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.

If you actually need to generate a pixmap with the blended image, you can use setOpacity on QPainter before drawing the pixmap on it.

like image 198
Pete Avatar answered Nov 03 '22 02:11

Pete