本页内容

GammaAdjust QML Type

调整源项的亮度。更多...

Import Statement: import Qt5Compat.GraphicalEffects
Since: QtGraphicalEffects 1.0
Inherits:

Item

属性

详细说明

GammaAdjust 会根据预先定义的幂律表达式曲线对每个像素进行处理,其中属性 gamma 用作倒数缩放指数。更多详细信息,请参阅gamma 的属性文档。

来源已应用的效果

叶子上的黑甲虫

应用了伽马校正的甲虫

示例

以下示例演示了如何应用该效果。

import QtQuick
import Qt5Compat.GraphicalEffects

Item {
    width: 300
    height: 300

    Image {
        id: bug
        source: "images/bug.jpg"
        sourceSize: Qt.size(parent.width, parent.height)
        smooth: true
        visible: false
    }

    GammaAdjust {
        anchors.fill: bug
        source: bug
        gamma: 0.45
    }
}

属性文档

cached : bool

此属性允许将效果输出像素缓存起来,以提升渲染性能。

每次更改源或效果属性时,都必须更新缓存中的像素。由于需要额外的内存缓冲区来存储效果输出,因此会增加内存消耗。

当源或效果属性进行动画处理时,建议禁用缓存。

默认情况下,该属性设置为false 。

gamma : real

该属性定义了每个像素亮度变化的系数,其计算依据如下公式:

luminance = pow(original_luminance, 1.0 / gamma); // The luminance is assumed to be between 0.0 and 1.0

将伽马值设置为小于 1.0 会使图像变暗,大于 1.0 则会使图像变亮。

该值的取值范围为 0.0(最暗)到 inf(最亮)。默认情况下,该属性设置为1.0 (无变化)。

不同伽马值的输出示例

暗色甲虫,伽马值 0.5

正常伽马射线下的甲虫

亮色甲虫,Gamma 2.0

gamma: 0.5 gamma: 1.0 gamma: 2.0
上述图像的像素亮度曲线。

伽马值为0.5时的亮度曲线

伽马值为1.0时的亮度曲线

伽马值为2.0时的亮度曲线

红色曲线:默认伽马值 (1.0)
黄色曲线:应用效果后
X 轴:像素原始亮度
Y轴:应用效果后的像素亮度

source : variant

此属性定义了将对其亮度进行调整的源项目。

注意: 不支持让效果包含自身,例如将“源”设置为该效果的父级。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.