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() = default;
63
64/*!
65 \qmlproperty bool QtMultimedia::ImageCapture::readyForCapture
66
67 This property holds a bool value indicating whether the camera
68 is ready to capture photos or not.
69
70 Calling capture() or captureToFile() while \e ready is \c false is not permitted and
71 results in an error.
72*/
73
74/*!
75 \qmlproperty string QtMultimedia::ImageCapture::preview
76
77 This property holds a url to the latest captured image. It can be connected to the
78 source property of an \l Image element to show the last captured image.
79
80 \qml
81 CaptureSession {
82 camera: Camera {}
83 imageCapture: ImageCapture {
84 id: capture
85 }
86 }
87 Image {
88 source: capture.preview
89 }
90 \endqml
91
92 \sa saveToFile
93*/
94
95/*!
96 \qmlmethod QtMultimedia::ImageCapture::capture()
97
98 Start image capture. The \l imageCaptured and \l imageSaved signals will
99 be emitted when the capture is complete.
100
101 The captured image will be available through the preview property that can be
102 used as the source for a QML Image item. The saveToFile() method can then be used
103 save the image.
104
105 Camera saves all the capture parameters like exposure settings or
106 image processing parameters, so changes to camera parameters after
107 capture() is called do not affect previous capture requests.
108
109 capture() returns the capture requestId parameter, used with
110 imageExposed(), imageCaptured(), imageMetadataAvailable() and imageSaved() signals.
111
112 \sa readyForCapture, preview
113*/
114
115/*!
116 \qmlmethod QtMultimedia::ImageCapture::captureToFile(location)
117
118 Does the same as capture() but additionally automatically saves the captured image to the specified
119 \a location.
120
121 \sa capture
122*/
123
125{
126 return m_capturedImagePath;
127}
128
129/*!
130 \qmlmethod QtMultimedia::ImageCapture::saveToFile(location)
131
132 Saves the last captured image to \a location.
133
134 \sa capture, preview
135*/
136void QQuickImageCapture::saveToFile(const QUrl &location) const
137{
138 m_lastImage.save(location.toLocalFile());
139}
140
141void QQuickImageCapture::_q_imageCaptured(int id, const QImage &preview)
142{
143 QString previewId = QStringLiteral("preview_%1").arg(id);
144 QQuickImagePreviewProvider::registerPreview(previewId, preview);
145 m_capturedImagePath = QStringLiteral("image://camera/%2").arg(previewId);
146 m_lastImage = preview;
147 emit previewChanged();
148}
149
150/*!
151 \qmlsignal QtMultimedia::ImageCapture::errorOccurred(id, error, errorString)
152
153 This signal is emitted when an error occurs during capture with requested \a id.
154 \a error is an enumeration of type ImageCapture::Error.
155 A descriptive message is available in \a errorString.
156*/
157
158/*!
159 \qmlsignal QtMultimedia::ImageCapture::imageCaptured(requestId, preview)
160
161 This signal is emitted when an image with requested id \a requestId has been captured
162 but not yet saved to the filesystem. The \a preview
163 parameter is the captured image.
164
165 \sa imageSaved, preview
166*/
167
168/*!
169 \qmlsignal QtMultimedia::ImageCapture::imageSaved(id, fileName)
170
171 This signal is emitted after the image with requested \a id has been written to the filesystem.
172 The \a fileName is a local file path, not a URL.
173
174 \sa imageCaptured
175*/
176
177
178/*!
179 \qmlsignal QtMultimedia::ImageCapture::imageMetadataAvailable(id, metaData)
180
181 This signal is emitted when the image with requested \a id has new \a metaData.
182
183 \sa imageCaptured
184*/
185
186
187QT_END_NAMESPACE
188
189#include "moc_qquickimagecapture_p.cpp"
QObject * parent
Definition qobject.h:73
\inmodule QtCore
Definition qobject.h:103
QString preview() const
\qmlproperty bool QtMultimedia::ImageCapture::readyForCapture
Combined button and popup list for selecting options.