如何在图像中制作渐变不透明度?

Sam*_*nte 2 qt gradient opacity qml qt5

如何使图像在qml中褪色?如何达到此效果?在这里我附上我想要它看起来的图像

在此处输入图片说明

eyl*_*esc 5

一种可能的解决方案是OpacityMaskLinearGradientas源一起使用

import QtQuick 2.9
import QtQuick.Window 2.2
import QtGraphicalEffects 1.0

Window {
    visible: true
    width: 600
    height: 600
    title: qsTr("Hello World")
    Image {
        id: input
        source: "input.jpg"
        anchors.fill: parent

        OpacityMask {
            source: mask
            maskSource: input
        }

        LinearGradient {
            id: mask
            anchors.fill: parent
            gradient: Gradient {
                GradientStop { position: 0.2; color: "transparent"}
                GradientStop { position: 0.5; color: "white" }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

输入:

在此处输入图片说明

输出:

在此处输入图片说明