管道多个QtGraphicalEffects效果

时间:2014-03-25 19:48:13

标签: c++ qml qt5

我有一个图像,我想在它上面应用两个QtGraphicalEffects效果:Blend(乘法模式)和Hue / Saturation。引自documentation

  

将多个效果组合在一起是创建偶数的简单方法   更令人印象深刻的输出。

Item {
    Image {
        id: image1
        source: "image1.png"
        visible: false
        smooth: true
    }

    Image {
        id: image2
        source: "image2.png"
        visible: false
        smooth: true
    }

    Blend {
        id: blendImage
        anchors.fill: image2
        source: image2
        foregroundSource: image1
        mode: "multiply"
        visible: false
    }

    HueSaturation {
        anchors.fill: image1
        source: image2
        saturation: -1.0
    }
}

此代码不会产生想要的结果,似乎混合丢失或甚至不考虑HueSaturation结果的输出。如何将效果一个接一个地管道?

1 个答案:

答案 0 :(得分:2)

如果你想合并你需要叠加它们的效果(第二个效果的来源必须是你的第一个效果)。

您只需将 HueSaturation 的来源更改为 blendImage

    HueSaturation {
            anchors.fill: image1
            source: blendImage
            saturation: -1.0
    }

试试这个:

    Item {
        Image {
            id: image1
            source: "image1.png"
            visible: false
            smooth: true
        }

        Image {
            id: image2
            source: "image2.png"
            visible: false
            smooth: true
        }

        Blend {
            id: blendImage
            anchors.fill: image2
            source: image2
            foregroundSource: image1
            mode: "multiply"
            visible: true
        }

        HueSaturation {
            anchors.fill: image1
            source: blendImage
            saturation: -1.0
        }
    }