#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{QGuiApplication app(argc, argv);QQmlApplicationEngine engine;engine.load(QUrl(QStringLiteral("qrc:/main.qml")));return app.exec();
}

程序的大部分源码是照着《qt  quick核心编程》书中的摄像头程序写的,但是源程序只是后置摄像头,我添加了调用前置摄像头,一点点改进

首先 FlatButton.qml  自定义有了一个按钮

import QtQuick 2.2
import QtQuick.Controls 1.2
Rectangle
{id:bkgnd;implicitWidth: 120;implicitHeight: 50color:"transparent";property  alias iconSource:icon.source;property  alias iconWidth:icon.width;property  alias  iconHeight:icon.height;property  alias textcolor:btnText.color;property  alias font:btnText.font;property  alias text:btnText.text;radius:6property bool hovered: false;border.color: "#949494";border.width: hovered ? 2:0;signal clicked;Image{id:icon;anchors.top: parent.top;anchors.topMargin: 5;//  anchors.margins: 4;anchors.horizontalCenter: parent.horizontalCenter;}Text{id:btnText;anchors.top: icon.bottom;anchors.horizontalCenter: icon.horizontalCenter;anchors.margins: 2;color: ma.pressed ? "blue" : (parent.hovered ? "#0000a0" : "white");}MouseArea{id:ma;anchors.fill:parent;hoverEnabled:true;onEntered: {bkgnd.hovered=true;}onExited: {bkgnd.hovered=false;}onClicked: {if(Qt.platform.os == "android"){bkgnd.hovered = false;}bkgnd.clicked();}}
}
main.qml实现了相机程序
import QtQuick 2.4
import QtQuick.Window 2.2
import QtMultimedia 5.4
import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1
Window {visible: truewidth:  Qt.platform.os === "android"? Screen.width: 640height:  Qt.platform.os === "android"? Screen.height: 480color:"black";property var cameras: QtMultimedia.availableCamerasproperty int currentCamera: 0FlatButton {id:qiehuananchors.right: parent.right;anchors.rightMargin: 2;anchors.top: parent.top;iconSource: "res/11.png";width:Qt.platform.os === "android"? Screen.width/8:70;height: Qt.platform.os === "android"? Screen.width/8:70;iconHeight: Qt.platform.os === "android"? Screen.width/10:84;iconWidth: Qt.platform.os === "android"? Screen.width/10:84;visible: true;z:1onClicked: {currentCamera++if (currentCamera >= cameras.length)currentCamera = 0camera.deviceId = cameras[currentCamera].deviceId}}Camera{id:camera;captureMode: Camera.CaptureStillImage;//捕获静态图像focus{focusMode:Camera.FocusAuto;//自动变焦focusPointMode: Camera.FocusPointCenter;//中心焦点}imageProcessing{whiteBalanceMode:CameraImageProcessing.WhiteBalanceAuto;//白平衡自动}flash.mode:Camera.FlashAuto;//闪光灯自动imageCapture{resolution: Qt.size(1920,1080);onImageCaptured: {camera.stop();photoPreview.visible=true;actionBar.visible=false;viewfinder.visible=false;photoPreview.source=preview;qiehuan.visible=false;}onImageSaved: {console.log(path);}}onLockStatusChanged:{switch(lockStatus){case Camera.Locked:imageCapture.captureToLocation("camera.jpg");unlock();break;case Camera.Searching:console.log("searching");break;case Camera.unlocked:console.log("unlocked");break;}}}VideoOutput{id:viewfinder;source: camera;focus:visible;anchors.fill:parent;autoOrientation: true;
}
Image{id:photoPreview;anchors.fill:parent;visible: false;fillMode: Image.PreserveAspectFit;FlatButton{iconSource: "res/ic_launcher_camera.png";width: Qt.platform.os === "android"? Screen.width/8: 76  ;height:  Qt.platform.os === "android"? Screen.width/8: 76  ;iconHeight: Qt.platform.os === "android"? Screen.width/10:84;iconWidth: Qt.platform.os === "android"? Screen.width/10:84;anchors.left: parent.left;anchors.bottom: parent.bottom;anchors.margins: 4;onClicked: {camera.start();actionBar.visible=true;viewfinder.visible=true;photoPreview.visible=false;qiehuan.visible=true;}}
}
Image
{id:actionBar;source:"res/control_bar.png";width:Qt.platform.os === "android"? Screen.width: 640;height:Qt.platform.os === "android"? Screen.height/10: 80;anchors.bottom: parent.bottom;anchors.bottomMargin: 8;anchors.horizontalCenter: parent.horizontalCenter;visible: true;z:1;FlatButton{id:shutter;anchors.centerIn: parent;iconSource: "res/ic_cam_shutter.png";width:Qt.platform.os === "android"? Screen.width/7:88;height: Qt.platform.os === "android"? Screen.width/7:88;iconHeight: Qt.platform.os === "android"? Screen.width/10:84;iconWidth: Qt.platform.os === "android"? Screen.width/10:84;onClicked: {camera.searchAndLock();//计算并锁定图像,触发锁定信号}}FlatButton{id:zoomout;anchors.verticalCenter: shutter.verticalCenter;anchors.right: shutter.left;anchors.rightMargin: 4;width:Qt.platform.os === "android"? Screen.width/7:70;height: Qt.platform.os === "android"? Screen.width/7:70;iconHeight: Qt.platform.os === "android"? Screen.width/10:84;iconWidth: Qt.platform.os === "android"? Screen.width/10:84;text:"缩小";font.pointSize: 12;iconSource: "res/ic_zoom_out.png";onClicked: {if(camera.digitalZoom>1)camera.digitalZoom=-0.5;}}
FlatButton{id:zoomin;anchors.verticalCenter: shutter.verticalCenter;anchors.right: zoomout.left;anchors.rightMargin: 4;width:Qt.platform.os === "android"? Screen.width/7:70;height: Qt.platform.os === "android"? Screen.width/7:70;iconHeight: Qt.platform.os === "android"? Screen.width/10:84;iconWidth: Qt.platform.os === "android"? Screen.width/10:84;text:"放大";font.pointSize: 12;iconSource: "res/ic_zoom_in.png";onClicked: {if(camera.digitalZoom<camera.maximumDigitalZoom)camera.digitalZoom+=0.5;}
}
FlatButton{id:currentFlath;anchors.verticalCenter: shutter.verticalCenter;anchors.left: shutter.right;anchors.leftMargin: 4;width:Qt.platform.os === "android"? Screen.width/7:70;height: Qt.platform.os === "android"? Screen.width/7:70;iconHeight: Qt.platform.os === "android"? Screen.width/10:84;iconWidth: Qt.platform.os === "android"? Screen.width/10:84;font.pointSize: 12;property var   moderIcon:["res/ic_menu_stat_flash_auto.png","res/ic_menu_stat_flash.png","res/ic_menu_stat_flash_off.png"]property var  moderDesc:["自动","打开","关闭"]property var flashMode: [Camera.FlashAuto, Camera.FlashOn, Camera.FlashOff]property int mode: 0;text: moderDesc[mode];iconSource: moderIcon[mode];onClicked: {mode = (mode + 1)%3;camera.flash.mode = flashMode[mode];}}
FlatButton{id:currentScense;anchors.verticalCenter: shutter.verticalCenter;anchors.left: currentFlath.right;anchors.leftMargin: 4;width:Qt.platform.os === "android"? Screen.width/7:70;height: Qt.platform.os === "android"? Screen.width/7:70;iconHeight: Qt.platform.os === "android"? Screen.width/10:84;iconWidth: Qt.platform.os === "android"? Screen.width/10:84;font.pointSize: 12;property var  modeIcon: ["res/ic_menu_stat_auto.png","res/ic_menu_stat_portrait.png","res/ic_menu_stat_landscape.png","res/ic_menu_stat_night.png","res/ic_menu_stat_action.png"]property var modeDesc:["自动","人物","风景","夜间","运动"]property var exposureMode:[Camera.ExposureAuto,Camera.ExposurePortrait,Camera.ExposureBeach,Camera.ExposureNight,Camera.ExposureSports]property int  mode:0;text:modeDesc[mode];iconSource: modeIcon[mode];onClicked: {mode=(mode+1)%5;camera.exposure.exposureMode=exposureMode[mode];}}}
}
main.cpp函数
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
}
在程序中加入了安卓程序启动画面
在andriod重点xml中加入
 <meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/splash"/>  
找到res/drawble文件夹中的splash照片是自己设置的开机启动图片

源码下载链接我的qt版本是5.6   http://download.csdn.net/detail/qq_28637193/9610336

用qt的qml写的安卓摄像头程序相关推荐

  1. 手把手教你写一个安卓app

    最近有很多小伙伴在后台留言:Android Studio.我想大家是想写一个手机app,前面已经分享了在QT上如何写一个安卓蓝牙app,虽然qt可以做app,但是比起Android Studio还是差 ...

  2. Qt Quick Qml 之QML与C++ 混合编程学习

    <QML与C++ 混合编程学习> 1. 在 QML 中使用 C++ 类和对象 1) C++ 类的修改 2) 注册 QML 类型 3) 在 QML 中导入类型 4) 在 QML 创建由 C+ ...

  3. QT调用C#写的Dll

    QT调用C#写的Dll 参见: https://blog.csdn.net/weixin_42420155/article/details/81060945 C#写的dll是没有dllMain入口函数 ...

  4. qt之qml开发优缺点_linux配置vlc-qt

    vlc-qt 是基于vlc库,用于开发音频视频应用,性能优秀. vlc-qt/vlc-qt​github.com 使用vlc-qt首先需要编译vlc-qt (windows可以下载使用编译好的,但是只 ...

  5. QT集成QML和JavaScript

    QT 集成QML和JavaScript 集成QML和JavaScript JavaScript表达式 JavaScript资源 JavaScript导入 JavaScript主机环境 精调JavaSc ...

  6. Qt与QML的枚举绑定(C++枚举)

    Qt到QML的枚举绑定 QML中是不支持c++的枚举类型的,所以我们可以使用Qt的元对象系统,即MOS,来帮助我们实现. 进行绑定的好处就是,以后数据发生变化的时候,就是枚举发生增加修改,添加等的时候 ...

  7. 基于Qt ffmpeg opengl开发跨平台安卓实时投屏软件

    [开源]基于Qt ffmpeg opengl开发跨平台安卓实时投屏软件 码云地址 https://gitee.com/Barryda/QtScrcpy github地址 https://github. ...

  8. 【Qt】QML快速入门7——输入元素

    QML快速入门 [Qt]QML快速入门1--语法:https://blog.csdn.net/See_Star/article/details/113729827 [Qt]QML快速入门2--基本元素 ...

  9. Qt Quick QML 实例之疯狂数字游戏(QML C++混合编程、翻译、QSetting )【建议收藏】

    文章目录 一.开门见山 二.最基本的框架(v0.1) 1. 后端数据处理 2. 导出 C++ 对象的 QML 的属性 3. 前台 UI 数据 三.完善执行逻辑(v0.2) 四.发布版本(v1.0) 1 ...

  10. Qt基于Qml图片翻转演示

    效果: qml源码 import QtQuick 2.12 import QtQuick.Controls 2.12ApplicationWindow {id: rootvisible: truewi ...

最新文章

  1. 在objective-c / cocoa中抛出异常
  2. 吴敏霞(为奥运冠军名字作诗)
  3. mysql 8.3_8.3 - mysql 表操作
  4. java 前端页面传过来的值怎么防止篡改_反爬虫,到底是怎么回事儿?
  5. C++和Rust_Kotlin、Rust两个充满了骚操作的编程语言,值得一玩
  6. C#笔记13 匿名类型、集合初始化器、扩展方法和查询表达式
  7. pandas小记:pandas数据输入输出
  8. 读懂 PetaLinux:让 Linux 在 Zynq 上轻松起“跑”(转)
  9. css旋转立方体教程,如何通过CSS3实现旋转立方体
  10. gbk英文字符占几个字节?
  11. python海龟隐藏_Python海龟绘图——常用方法指令
  12. Python数据交互式可视化 - 交互式可视化
  13. Acwing 2944. 回家的路
  14. [转]漫画:混乱的标记语言XHTML2/HTML5(附中文版翻译)
  15. MIPS汇编语言学习笔记23:if 语句分支指令
  16. Geoffrey Hinton:我的五十年深度学习生涯与研究心法
  17. LoRaWAN 协议规范
  18. 给校园招聘中应聘嵌入式程序员的几点建议
  19. 基于FPGA的CNN卷积神经网络加速器
  20. Mathtype卸载问题,使用期限、还有与word关联问题,The MathType DLL cannot be found.问题解决方法、查找office安装路径

热门文章

  1. C# 中 动态获得或设置一个对象的值
  2. WPF下通过附加属性实现单实例启动
  3. git 拉取某个分支到本地
  4. centos 6.4 使用sendmail发送邮件(cacti)
  5. $().index() 两种用法
  6. [不得不转载]一个时代的结束:微软盖茨的人生掠影
  7. springboot项目中使用spring的xml文件
  8. [MapReduce_8] MapReduce 中的自定义分区实现
  9. Git安装遇到的问题fatal: Could not read from remote repository.的解决办法
  10. nginx 逻辑运算