1、概述
FastBlur 是 QML 中 QtGraphicalEffects 模块提供的一个组件,用于在 Qt Quick 应用程序中实现快速模糊效果。它可以应用于任何图像、矩形或其他可视项,使其看起来模糊和不清晰。FastBlur 使用了源内容缩小和双线性过滤的算法来模糊源内容,从而软化源内容。虽然其模糊质量低于高斯模糊(GaussianBlur),但渲染速度更快,适用于源内容快速变化且不需要最高模糊质量的场景。
2、重要属性
cached
:bool 类型,用于缓存效果输出像素,以提高渲染性能。但每次更改源或效果属性时,都必须更新缓存中的像素,会增加内存消耗。因此,在源属性或效果属性设置动画时建议禁用缓存。radius
:real 类型,定义影响单个像素模糊的相邻像素的距离。较大的半径会增加模糊效果。但请注意,FastBlur 算法可能会在内部降低半径的精度,以提供良好的渲染性能。该值的范围为 0.0(无模糊)到正无穷大。当半径超过 64 时,模糊的视觉质量可能会降低。source
:variant 类型,指定要模糊的源项。transparentBorder
:bool 类型,定义项目边缘附近的模糊行为。如果设置为 true,则源外部的像素将被解释为透明的,模糊效果会在效果项区域外稍微展开。如果设置为 false,则源之外的像素将被解释为包含与项目边缘像素相同的颜色,模糊效果不会扩展到效果项区域之外。默认为 false。
Window {
width: 480; height: 240
visible: true
Rectangle {
width: 480
height: 240
color: '#1e1e1e'
Row {
anchors.centerIn: parent
spacing: 16
Image {
id: sourceImage
source: "res/0.jpg"
width: 200
height: width
sourceSize: Qt.size(parent.width, parent.height)
smooth: true
}
FastBlur {
width: 200
height: width
source: sourceImage
radius: blurred ? 32 : 0
property bool blurred: false
Behavior on radius {
NumberAnimation {
duration: 1000
}
}
MouseArea {
id: area
anchors.fill: parent
onClicked: {
parent.blurred = !parent.blurred
}
}
}
}
}
}
觉得有帮助的话,打赏一下呗。。
需要商务合作(定制程序)的欢迎私信!!