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