概述
额…什么都不说了,直接看代码吧
Item{
id:item
anchors.fill: parent
Camera {
id: camera
focus {
focusMode: Camera.FocusAuto;
focusPointMode: Camera.FocusPointCenter;
}
captureMode: Camera.CaptureStillImage;
imageProcessing {
whiteBalanceMode: CameraImageProcessing.WhiteBalanceAuto;
}
flash.mode: Camera.FlashAuto;
imageCapture {
onImageCaptured: {
// Show the preview in an Image
photoPreview.source = preview
}
}
}
VideoOutput {
id:viewfinder
source: camera
fillMode: Stretch
focus : visible // to receive focus and capture key events when visible
anchors.fill: parent
autoOrientation: true
MouseArea{
anchors.fill: parent
onClicked: {
camera.searchAndLock();
}
}
}
ZoomControl {
id:zoomControl
x : 0
y : 0
z:3
width : 100
height: parent.height
currentZoom: camera.digitalZoom
maximumZoom: Math.min(4.0, camera.maximumDigitalZoom)
onZoomTo: camera.setDigitalZoom(value)
}
TLImageButton{
id:captureBtn
width: 60
height: width
picNormal:commonParameter.getSkinPath() + "icon_capture_normal.png"
picPressed: commonParameter.getSkinPath() + "icon_capture_press.png"
picHover: commonParameter.getSkinPath() + "icon_capture_normal.png"
anchors.bottom: parent.bottom
anchors.bottomMargin: 8*initWidth/375.0
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
camera.imageCapture.capture()
}
}
}
Image {id: photoPreview}
ZoomControl是自定义的一个滑动条,用于设置拍照焦距的.来看看滑动条代码.
import QtQuick 2.0
import QtMultimedia 5.0
Item {
id : zoomControl
property real currentZoom : 1
property real maximumZoom : 1
signal zoomTo(real value)
visible: zoomControl.maximumZoom > 1
MouseArea {
id : mouseArea
anchors.fill: parent
property real initialZoom : 0
property real initialPos : 0
onPressed: {
initialPos = mouseY
initialZoom = 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 : bar
x : 16
y : parent.height/4
width : 24
height : parent.height/2
Rectangle {
anchors.fill: parent
smooth: true
radius: 8
border.color: "white"
border.width: 2
color: "black"
opacity: 0.3
}
Rectangle {
id: groove
x : 0
y : parent.height * (1.0 - (zoomControl.currentZoom-1.0) / (zoomControl.maximumZoom-1.0))
width: parent.width
height: parent.height - y
smooth: true
radius: 8
color: "white"
opacity: 0.5
}
Text {
id: zoomText
anchors {
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) / 100
font.bold: true
color: "white"
style: Text.Raised; styleColor: "black"
opacity: 0.85
font.pixelSize: 18
}
}
}
OK 所有代码已奉上.逻辑很简单.
最后
以上就是单薄唇膏为你收集整理的QML Camera 摄像头拍照(带滑动条设置焦距)的全部内容,希望文章能够帮你解决QML Camera 摄像头拍照(带滑动条设置焦距)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复