Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickimagecapture.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
include
"qquickimagecapture_p.h"
5
#
include
"qquickimagepreviewprovider_p.h"
6
7
#
include
<
QtCore
/
qurl
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
/*!
12
\qmltype ImageCapture
13
\nativetype QQuickImageCapture
14
\brief An interface for capturing camera images.
15
\ingroup multimedia_qml
16
\inqmlmodule QtMultimedia
17
\ingroup camera_qml
18
19
This type allows you to capture still images and be notified when they
20
are available or saved to disk.
21
22
\qml
23
Item {
24
width: 640
25
height: 360
26
27
CaptureSession {
28
imageCapture : ImageCapture {
29
id: imageCapture
30
}
31
camera: Camera {
32
id: camera
33
}
34
35
videoOutput: videoOutput
36
}
37
VideoOutput {
38
id: videoOutput
39
anchors.fill: parent
40
41
MouseArea {
42
anchors.fill: parent;
43
onClicked: imageCapture.capture();
44
}
45
}
46
47
Image {
48
id: photoPreview
49
source: imageCapture.preview // always shows the last captured image
50
}
51
}
52
\endqml
53
54
*/
55
56
QQuickImageCapture
::
QQuickImageCapture
(
QObject
*
parent
)
57
:
QImageCapture
(
parent
)
58
{
59
connect(
this
, &QImageCapture::imageCaptured,
this
, &QQuickImageCapture::_q_imageCaptured);
60
}
61
62
QQuickImageCapture::~QQuickImageCapture()
63
{
64
QQuickImagePreviewProvider::cleanupInstance(m_instanceId);
65
}
66
67
/*!
68
\qmlproperty bool QtMultimedia::ImageCapture::readyForCapture
69
70
This property holds a bool value indicating whether the camera
71
is ready to capture photos or not.
72
73
Calling capture() or captureToFile() while \e ready is \c false is not permitted and
74
results in an error.
75
*/
76
77
/*!
78
\qmlproperty string QtMultimedia::ImageCapture::preview
79
80
This property holds a url to the latest captured image. It can be connected to the
81
source property of an \l Image element to show the last captured image.
82
83
\qml
84
CaptureSession {
85
camera: Camera {}
86
imageCapture: ImageCapture {
87
id: capture
88
}
89
}
90
Image {
91
source: capture.preview
92
}
93
\endqml
94
95
\sa saveToFile
96
*/
97
98
/*!
99
\qmlmethod int QtMultimedia::ImageCapture::capture()
100
101
Start image capture. The \l imageCaptured and \l imageSaved signals will
102
be emitted when the capture is complete.
103
104
The captured image will be available through the preview property that can be
105
used as the source for a QML Image item. The saveToFile() method can then be used
106
save the image.
107
108
Camera saves all the capture parameters like exposure settings or
109
image processing parameters, so changes to camera parameters after
110
capture() is called do not affect previous capture requests.
111
112
capture() returns the capture requestId parameter, used with
113
imageExposed(), imageCaptured(), imageMetadataAvailable() and imageSaved() signals.
114
115
\sa readyForCapture, preview
116
*/
117
118
/*!
119
\qmlmethod int QtMultimedia::ImageCapture::captureToFile(location)
120
121
Does the same as capture() but additionally automatically saves the
122
captured image to the specified \a location. Returns the capture
123
requestId parameter.
124
125
\sa capture()
126
*/
127
128
QString
QQuickImageCapture
::
preview
()
const
129
{
130
return
m_capturedImagePath;
131
}
132
133
/*!
134
\qmlmethod void QtMultimedia::ImageCapture::saveToFile(location)
135
136
Saves the last captured image to \a location.
137
138
\sa capture, preview
139
*/
140
void
QQuickImageCapture
::saveToFile(
const
QUrl &location)
const
141
{
142
m_lastImage.save(location.toLocalFile());
143
}
144
145
void
QQuickImageCapture
::_q_imageCaptured(
int
id,
const
QImage &preview)
146
{
147
QString previewId =
148
QStringLiteral(
"preview_%1_%2"
).arg(m_instanceId.toString(QUuid::Id128)).arg(id);
149
QQuickImagePreviewProvider::registerPreview(m_instanceId, previewId, preview);
150
m_capturedImagePath = QStringLiteral(
"image://QtMultimediaCameraPreviewImageProvider/%2"
).arg(previewId);
151
m_lastImage = preview;
152
emit previewChanged();
153
}
154
155
/*!
156
\qmlsignal QtMultimedia::ImageCapture::errorOccurred(id, error, errorString)
157
158
This signal is emitted when an error occurs during capture with requested \a id.
159
\a error is an enumeration of type ImageCapture::Error.
160
A descriptive message is available in \a errorString.
161
162
\sa error errorString
163
*/
164
165
/*!
166
\qmlsignal QtMultimedia::ImageCapture::imageCaptured(requestId, preview)
167
168
This signal is emitted when an image with requested id \a requestId has been captured
169
but not yet saved to the filesystem. The \a preview
170
parameter is the captured image.
171
172
\sa imageSaved, preview
173
*/
174
175
/*!
176
\qmlsignal QtMultimedia::ImageCapture::imageSaved(id, fileName)
177
178
This signal is emitted after the image with requested \a id has been written to the filesystem.
179
The \a fileName is a local file path, not a URL.
180
181
\sa imageCaptured
182
*/
183
184
185
/*!
186
\qmlsignal QtMultimedia::ImageCapture::imageMetadataAvailable(id, metaData)
187
188
This signal is emitted when the image with requested \a id has new \a metaData.
189
190
\sa imageCaptured
191
*/
192
193
194
QT_END_NAMESPACE
195
196
#
include
"moc_qquickimagecapture_p.cpp"
QObjectData::parent
QObject * parent
Definition
qobject.h:74
QObject
\inmodule QtCore
Definition
qobject.h:106
QQuickImageCapture
Definition
qquickimagecapture_p.h:30
QQuickImageCapture::preview
QString preview() const
\qmlproperty bool QtMultimedia::ImageCapture::readyForCapture
Definition
qquickimagecapture.cpp:128
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qrandomaccessasyncfile_darwin.mm:17
qtmultimedia
src
multimediaquick
qquickimagecapture.cpp
Generated on
for Qt by
1.16.1