QML Camera 摄像头拍照(带滑动条设置焦距)
生活随笔
收集整理的這篇文章主要介紹了
QML Camera 摄像头拍照(带滑动条设置焦距)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
額…什么都不說了,直接看代碼吧
Item{id:itemanchors.fill: parentCamera {id: camerafocus {focusMode: Camera.FocusAuto;focusPointMode: Camera.FocusPointCenter;}captureMode: Camera.CaptureStillImage;imageProcessing {whiteBalanceMode: CameraImageProcessing.WhiteBalanceAuto;}flash.mode: Camera.FlashAuto;imageCapture {onImageCaptured: {// Show the preview in an ImagephotoPreview.source = preview}}}VideoOutput {id:viewfindersource: camerafillMode: Stretchfocus : visible // to receive focus and capture key events when visibleanchors.fill: parentautoOrientation: trueMouseArea{anchors.fill: parentonClicked: {camera.searchAndLock();}}}ZoomControl {id:zoomControlx : 0y : 0z:3width : 100height: parent.heightcurrentZoom: camera.digitalZoommaximumZoom: Math.min(4.0, camera.maximumDigitalZoom)onZoomTo: camera.setDigitalZoom(value)}TLImageButton{id:captureBtnwidth: 60height: widthpicNormal:commonParameter.getSkinPath() + "icon_capture_normal.png"picPressed: commonParameter.getSkinPath() + "icon_capture_press.png"picHover: commonParameter.getSkinPath() + "icon_capture_normal.png"anchors.bottom: parent.bottomanchors.bottomMargin: 8*initWidth/375.0anchors.horizontalCenter: parent.horizontalCenteronClicked: {camera.imageCapture.capture()}}}Image {id: photoPreview}ZoomControl是自定義的一個滑動條,用于設置拍照焦距的.來看看滑動條代碼.
import QtQuick 2.0 import QtMultimedia 5.0Item {id : zoomControlproperty real currentZoom : 1property real maximumZoom : 1signal zoomTo(real value)visible: zoomControl.maximumZoom > 1MouseArea {id : mouseAreaanchors.fill: parentproperty real initialZoom : 0property real initialPos : 0onPressed: {initialPos = mouseYinitialZoom = zoomControl.currentZoom}onPositionChanged: {if (pressed) {var target = initialZoom * Math.pow(5, (initialPos-mouseY)/zoomControl.height);target = Math.max(1, Math.min(target, zoomControl.maximumZoom))zoomControl.zoomTo(target)}}}Item {id : barx : 16y : parent.height/4width : 24height : parent.height/2Rectangle {anchors.fill: parentsmooth: trueradius: 8border.color: "white"border.width: 2color: "black"opacity: 0.3}Rectangle {id: groovex : 0y : parent.height * (1.0 - (zoomControl.currentZoom-1.0) / (zoomControl.maximumZoom-1.0))width: parent.widthheight: parent.height - ysmooth: trueradius: 8color: "white"opacity: 0.5}Text {id: zoomTextanchors {left: bar.right; leftMargin: 16}y: Math.min(parent.height - height, Math.max(0, groove.y - height / 2))text: "x" + Math.round(zoomControl.currentZoom * 100) / 100font.bold: truecolor: "white"style: Text.Raised; styleColor: "black"opacity: 0.85font.pixelSize: 18}} }OK 所有代碼已奉上.邏輯很簡單.
總結
以上是生活随笔為你收集整理的QML Camera 摄像头拍照(带滑动条设置焦距)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt for Android获取手机序列
- 下一篇: Android判断网线连接