Qt的QPainter::CompositionMode提供了多种图像叠加的模式。常见的有QPainter::CompositionMode_SourceOver, QPainter::CompositionMode_SourceAtop,
QPainter::CompositionMode_DestinationOver和QPainter::CompositionMode_DestinationAtop。
实现多张图片重叠绘制显示的方式如下:
QImage resultImage=image;
QImage sourceImage=image1;
QPainter painter(&resultImage);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(resultImage.rect(), Qt::transparent);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawImage(0, 0, sourceImage);
painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
painter.fillRect(resultImage.rect(), QColor(0, 0, 0, alpha));
painter.end();