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
6
7#include <QtCore/qurl.h>
8
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
58{
59 connect(this, &QImageCapture::imageCaptured, this, &QQuickImageCapture::_q_imageCaptured);
60}
61
62QQuickImageCapture::~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 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 QtMultimedia::ImageCapture::captureToFile(location)
120
121 Does the same as capture() but additionally automatically saves the captured image to the specified
122 \a location.
123
124 \sa capture
125*/
126
128{
129 return m_capturedImagePath;
130}
131
132/*!
133 \qmlmethod QtMultimedia::ImageCapture::saveToFile(location)
134
135 Saves the last captured image to \a location.
136
137 \sa capture, preview
138*/
139void QQuickImageCapture::saveToFile(const QUrl &location) const
140{
141 m_lastImage.save(location.toLocalFile());
142}
143
144void QQuickImageCapture::_q_imageCaptured(int id, const QImage &preview)
145{
146 QString previewId =
147 QStringLiteral("preview_%1_%2").arg(m_instanceId.toString(QUuid::Id128)).arg(id);
148 QQuickImagePreviewProvider::registerPreview(m_instanceId, previewId, preview);
149 m_capturedImagePath = QStringLiteral("image://QtMultimediaCameraPreviewImageProvider/%2").arg(previewId);
150 m_lastImage = preview;
151 emit previewChanged();
152}
153
154/*!
155 \qmlsignal QtMultimedia::ImageCapture::errorOccurred(id, error, errorString)
156
157 This signal is emitted when an error occurs during capture with requested \a id.
158 \a error is an enumeration of type ImageCapture::Error.
159 A descriptive message is available in \a errorString.
160
161 \sa error errorString
162*/
163
164/*!
165 \qmlsignal QtMultimedia::ImageCapture::imageCaptured(requestId, preview)
166
167 This signal is emitted when an image with requested id \a requestId has been captured
168 but not yet saved to the filesystem. The \a preview
169 parameter is the captured image.
170
171 \sa imageSaved, preview
172*/
173
174/*!
175 \qmlsignal QtMultimedia::ImageCapture::imageSaved(id, fileName)
176
177 This signal is emitted after the image with requested \a id has been written to the filesystem.
178 The \a fileName is a local file path, not a URL.
179
180 \sa imageCaptured
181*/
182
183
184/*!
185 \qmlsignal QtMultimedia::ImageCapture::imageMetadataAvailable(id, metaData)
186
187 This signal is emitted when the image with requested \a id has new \a metaData.
188
189 \sa imageCaptured
190*/
191
192
193QT_END_NAMESPACE
194
195#include "moc_qquickimagecapture_p.cpp"
QObject * parent
Definition qobject.h:73
\inmodule QtCore
Definition qobject.h:105
QString preview() const
\qmlproperty bool QtMultimedia::ImageCapture::readyForCapture
Combined button and popup list for selecting options.