-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCameraWindow.qml
executable file
·156 lines (141 loc) · 4.69 KB
/
CameraWindow.qml
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import QtQuick 2.5
import QtMultimedia 5.6
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
SystemWindow {
id: root
property int adaptive_width: Screen.desktopAvailableWidth
property int adaptive_height: Screen.desktopAvailableHeight
width: adaptive_width
height: adaptive_height
// width: def.win_width
// height: def.win_height
//// color: "black"
//// title: qsTr("相机")
//// flags: Qt.Dialog //Dialog,没有最大最小化按钮
// property bool showFlag: false
// function show(){
// open()
// }
// function showNormal(){
// open()
// }
onVisibleChanged: {
if(showFlag == false)
{
showFlag = true;
camera.start()
console.log("相机窗口被激活")
}
}
onAboutToHide: {
showFlag = false
camera.stop()
}
Component.onCompleted: camera.stop()
Define {id: def}
Album {id: w_album}
Camera {
id: camera
//相机模式
// captureMode: Camera.CaptureStillImage //静态照片捕捉模式
captureMode: Camera.CaptureStillImage
//白平衡
imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash
//分辨率
viewfinder.resolution: "320x240"
flash.mode: Camera.FlashRedEyeReduction
//曝光
exposure {
exposureCompensation: +1.0
exposureMode: Camera.ExposurePortrait
}
//拍照模式配置
imageCapture {
onImageSaved: console.log("save path:" + path);
onImageCaptured: bar.img_src = preview
onCaptureFailed: console.log("capture failed:" + message)
}
//录像模式配置
videoRecorder {
// resolution: "640x480"
frameRate: 30 //帧率
// audioEncodingMode: CameraRecorder.ConstantBitrateEncoding;
// audioBitRate: 128000 //视频比特率
// mediaContainer: "mp4" //视频录制格式
// outputLocation: "D:\MYIR\Capture\video_test" //保存地址
onRecorderStateChanged: console.log("state changed")
onRecorderStatusChanged: console.log("status changed")
}
//对焦模式
// focus {
// focusMode: Camera.FocusAuto
// focusPointMode: Camera.FocusPointCenter
// }
onError: console.log("camera err: " + errorCode + errorString);
Component.onCompleted: console.log('StackView.onStatusChanged camera.viewfinder.resolution:', camera.viewfinder.resolution)
}
VideoOutput {
anchors.fill: parent
source: camera
}
ListModel {id: imagePaths}
//相机界面,左上角返回按钮
MyIconButton {
id: backButton
icon_code: def.iconCode_back
button_text: camera.displayName
button_color: "white"
anchors.left: parent.left
anchors.top: parent.top
anchors.margins: 10
onClicked: {
camera.stop()
root.close()
}
}
//右上角跳转到图库按钮
MyIconButton {
id: albumButton
icon_code: def.iconCode_album
button_text: qsTr("所有图片")
button_color: "white"
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: 10
onClicked: {
w_album.setImageFolder(def.imageDefaultLocation)
w_album.showNormal()
}
}
//底部拍照功能区域:预览图片+矩形+按钮
CaptureBar {
id: bar
anchors.bottom: parent.bottom
anchors.right: parent.right
onCaptureImage: {
//保存照片到指定位置
var savePath = def.captureSavePath + def.captureSaveHead + def.getCurrentTime();
camera.imageCapture.captureToLocation(savePath);
}
//以下为小视频录制功能
onCaptureVideoStart: {
console.log("capture video start")
/*
camera.captureMode = Camera.CaptureVideo
var savePath = def.captureSavePath + "video_" + def.getCurrentTime();
camera.videoRecorder.setOutputLocation(savePath)
camera.videoRecorder.record()
*/
}
onCaptureVideoStop: {
console.log("capture video stop")
/*
camera.videoRecorder.stop()
camera.captureMode = Camera.CaptureStillImage
camera.start()
*/
}
}
}