我是靠谱客的博主 单薄唇膏,这篇文章主要介绍QML Camera 摄像头拍照(带滑动条设置焦距),现在分享给大家,希望可以做个参考。

额…什么都不说了,直接看代码吧

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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是自定义的一个滑动条,用于设置拍照焦距的.来看看滑动条代码.

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部