Qml 和模糊图像 [英] Qml and blurring image

查看:9
本文介绍了Qml 和模糊图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 QML 实现模糊效果.我找到了关于效果:模糊"(示例) 但在 Qt 4.8 中这不起作用.据我所知,这是用 C++ 代码实现的.但是怎么做呢?

I want to achieve a blur effect using QML. I found references about the "effect: Blur"(Example) but in Qt 4.8 this does not work. As far as I know this is implemented with C++ code. But how?

推荐答案

effect 属性,所有视觉 QML 项目都有,接受所有作为 QGraphicsEffect.Qt 4.8 附带 QGraphicsBlurEffectQGraphicsColorizeEffectQGraphicsDropShadowEffectQGraphicsOpacityEffect.最初这些默认情况下都在 QML 中可用,但有一次在开发中(在 QtQuick 的第一个公开版本之前),出于性能原因,它们被排除在外.为了让它们再次工作,必须在他的应用程序的 C++ 部分中包含以下代码行,例如在 main 函数中:

The effect attribute, wich all visual QML items have, accepts all the effects which are subclasses of QGraphicsEffect. Qt 4.8 ships with QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsDropShadowEffect, and QGraphicsOpacityEffect. Originally these there all available in QML by default, but at one time in development (before the first public release of QtQuick) they were excluded for performance reasons. To make them work again, one has to include the following lines of code in the C++ part of his application, for instance in the main function:

qmlRegisterType<QGraphicsBlurEffect>("Effects",1,0,"Blur");
qmlRegisterType<QGraphicsColorizeEffect>("Effects",1,0,"Colorize");
qmlRegisterType<QGraphicsDropShadowEffect>("Effects",1,0,"DropShadow");
qmlRegisterType<QGraphicsOpacityEffect>("Effects",1,0,"OpacityEffect");

这使得这些类可用于 QML,因此人们可以像这样使用它们:

This make these classes available to QML so one can use them like:

import QtQuick 1.1
import Effects 1.0

Item {
    // [...]
    effect: Blur {
        blurRadius: 10.0
    }
}

这可行,但在许多情况下,由此产生的性能确实令人无法接受.然后你应该尝试在 ShaderEffectItem.这样一来,人们就可以使用 GLSL 着色器程序实现图形效果,从而实现 GPU 渲染,这比旧的基于 QGraphicsEffect 的方法要快得多.

This works, but in many case the resulting performance is really unacceptable. Then you should try to implement blurring with the help of ShaderEffectItem. That way one can realize graphic effects with GLSL shader programs resulting in GPU rendering which is way faster than the old QGraphicsEffect-based approach.

这篇关于Qml 和模糊图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆