QML 图形渲染 - ThresholdMask

作者:billy
版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处

属性介绍

  • cached : bool
    使用缓存效果输出像素,可以提高渲染性能。每次更改源或效果属性时,都必须更新缓存中的像素。会增加内存消耗,因为存储效果输出需要额外的内存缓冲区。所以我们建议在源属性或效果属性设置动画时禁用缓存。默认为 false

  • maskSource : variant
    用作掩码的项。遮罩项渲染到中间像素缓冲区中,结果中的 alpha 值用于确定源项在显示中的像素可见性。
    注意:不支持让效果包含自身

  • source : variant
    要屏蔽的源项。注意:不支持让效果包含自身

  • spread : real
    接近 “阈值alpha” 值的遮罩边的平滑度。将 spread 设置为 0.0 通常使用具有指定阈值的掩码。通过在透明遮罩像素和不透明遮罩像素之间添加插值,设置更高的扩展值可以软化从透明遮罩像素到不透明遮罩像素的过渡。该值的范围为 0.0(锐化遮罩边缘)到 1.0(平滑遮罩边缘)。默认情况下,该属性设置为 0.0

  • threshold : real
    遮罩像素的阈值。alpha 值低于此属性的遮罩像素用于完全遮罩源项的相应像素。具有较高 alpha 值的遮罩像素用于将源项与显示器进行 alpha 混合。该值的范围为 0.0(alpha 值 0)到 1.0(alpha 值 255)。默认情况下,该属性设置为 0.0

注意事项

  1. ThresholdMask 支持 OpenGL 渲染
  2. ThresholdMask 可以使用遮罩像素的阈值来控制遮罩行为

不同数值效果展示

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

官方示例

import QtQuick 2.12
import QtGraphicalEffects 1.12

Item {
    width: 300
    height: 300
    
    Image {
        id: background
        anchors.fill: parent
        source: "images/checker.png"
        smooth: true
        fillMode: Image.Tile
    }
    
    Image {
        id: bug
        source: "images/bug.jpg"
        sourceSize: Qt.size(parent.width, parent.height)
        smooth: true
        visible: false
    }
    
    Image {
        id: mask
        source: "images/fog.png"
        sourceSize: Qt.size(parent.width, parent.height)
        smooth: true
        visible: false
    }
    
    ThresholdMask {
        anchors.fill: bug
        source: bug
        maskSource: mask
        threshold: 0.4
        spread: 0.2
    }
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_34139994/article/details/120053652
QML