首页 技术 正文
技术 2022年11月14日
0 收藏 584 点赞 4,643 浏览 1964 个字

有兴趣的开发人员能够參阅连接http://doc.qt.io/qt-5/qtgraphicaleffects-qmlmodule.html来深度学习Qt对Graphics方面的处理。

在今天的这篇文章中。我们来使用OpacityMask做一个小小的样例来抛砖引玉看看Qt对我们的图像的处理。

详细的样例在Qt的官方站点上能够看到。因为一些原因,在官方站点上下载的例程中的文件并不能被使用,须要做一些的处理才干够。

以下,我们直接来把我们的样例展示给大家:

import QtQuick 2.0
import Ubuntu.Components 1.1
import QtGraphicalEffects 1.0/*!
\brief MainView with a Label and Button elements.
*/MainView {
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest
applicationName: "mask.liu-xiao-guo" /*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
//automaticOrientation: true // Removes the old toolbar and enables new features of the new header.
useDeprecatedToolbar: false width: units.gu(60)
height: units.gu(85) Page {
title: i18n.tr("mask") Flickable {
anchors.fill: parent
contentHeight: mypics.childrenRect.height Item {
id: mypics
width: parent.width
height: units.gu(80) Image {
id: bug
height: parent.height/2
width: height
source: "images/bug.png"
sourceSize: Qt.size(parent.width, parent.height)
smooth: true
visible: false
} Image {
id: bug1
height: parent.height/2
width: height
source: "images/bug.png"
anchors.top: bug.bottom
anchors.topMargin: units.gu(1)
sourceSize: Qt.size(parent.width, parent.height)
smooth: true
visible: false
} Rectangle {
id: mask
anchors.margins: 10
width: 65
height: 65
color: "black"
radius: width/2
clip: true
visible: false
} Image {
id: mask1
height: units.gu(40)
width: height
source: "images/bufferfly.png"
sourceSize: Qt.size(parent.width, parent.height)
smooth: true
visible: false
} OpacityMask {
anchors.fill: bug
source: bug
maskSource: mask
} OpacityMask {
anchors.fill: bug1
source: bug
maskSource: mask1
}
}
}
}
}

在这里。我们使用了Image来展示图片,可是。他们并非可见的(visible = false)。我们能够通过一个掩膜mask,在mask上值为非透明的地方能够显示出图像。

能够通过OpacityMask来使得它们能够显示。

我们的mask图片bufferfly.png例如以下:

bug.png的原图为:

执行我们的例程,效果图例如以下:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center” width=”200″ height=”300″ alt=””>  

源代码在: https://github.com/liu-xiao-guo/mask

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905