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#ifndef QCAMERAIMAGECAPTURE_H
5#define QCAMERAIMAGECAPTURE_H
6
7#include <QtCore/qobject.h>
8#include <QtMultimedia/qvideoframe.h>
9
10#include <QtMultimedia/qmediaenumdebug.h>
11
12QT_BEGIN_NAMESPACE
13
14class QSize;
15class QMediaMetaData;
16QT_END_NAMESPACE
17
18QT_BEGIN_NAMESPACE
19
20class QImageEncoderSettings;
21class QCamera;
22class QMediaCaptureSession;
23
24class QImageCapturePrivate;
25class Q_MULTIMEDIA_EXPORT QImageCapture : public QObject
26{
27 Q_OBJECT
28 Q_PROPERTY(bool readyForCapture READ isReadyForCapture NOTIFY readyForCaptureChanged)
29 Q_PROPERTY(QMediaMetaData metaData READ metaData WRITE setMetaData NOTIFY metaDataChanged)
30 Q_PROPERTY(Error error READ error NOTIFY errorChanged)
31 Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
32 Q_PROPERTY(FileFormat fileFormat READ fileFormat NOTIFY setFileFormat NOTIFY fileFormatChanged)
33 Q_PROPERTY(Quality quality READ quality NOTIFY setQuality NOTIFY qualityChanged)
34public:
35 enum Error
36 {
37 NoError,
38 NotReadyError,
39 ResourceError,
40 OutOfSpaceError,
41 NotSupportedFeatureError,
42 FormatError
43 };
44 Q_ENUM(Error)
45
46 enum Quality
47 {
48 VeryLowQuality,
49 LowQuality,
50 NormalQuality,
51 HighQuality,
52 VeryHighQuality
53 };
54 Q_ENUM(Quality)
55
56 enum FileFormat {
57 UnspecifiedFormat,
58 JPEG,
59 PNG,
60 WebP,
61 Tiff,
62 LastFileFormat = Tiff
63 };
64 Q_ENUM(FileFormat)
65
66 explicit QImageCapture(QObject *parent = nullptr);
67 ~QImageCapture();
68
69 bool isAvailable() const;
70
71 QMediaCaptureSession *captureSession() const;
72
73 Error error() const;
74 QString errorString() const;
75
76 bool isReadyForCapture() const;
77
78 FileFormat fileFormat() const;
79 void setFileFormat(FileFormat format);
80
81 static QList<FileFormat> supportedFormats();
82 static QString fileFormatName(FileFormat c);
83 static QString fileFormatDescription(FileFormat c);
84
85 QSize resolution() const;
86 void setResolution(const QSize &);
87 void setResolution(int width, int height);
88
89 Quality quality() const;
90 void setQuality(Quality quality);
91
92 QMediaMetaData metaData() const;
93 void setMetaData(const QMediaMetaData &metaData);
94 void addMetaData(const QMediaMetaData &metaData);
95
96public Q_SLOTS:
97 int captureToFile(const QString &location = QString());
98 int capture();
99
100Q_SIGNALS:
101 void errorChanged();
102 void errorOccurred(int id, QImageCapture::Error error, const QString &errorString);
103
104 void readyForCaptureChanged(bool ready);
105 void metaDataChanged();
106
107 void fileFormatChanged();
108 void qualityChanged();
109 void resolutionChanged();
110
111 void imageExposed(int id);
112 void imageCaptured(int id, const QImage &preview);
113 void imageMetadataAvailable(int id, const QMediaMetaData &metaData);
114 void imageAvailable(int id, const QVideoFrame &frame);
115 void imageSaved(int id, const QString &fileName);
116
117private:
118 // This is here to flag an incompatibilities with Qt 5
119 QImageCapture(QCamera *) = delete;
120
121 friend class QMediaCaptureSession;
122 class QPlatformImageCapture *platformImageCapture();
123 void setCaptureSession(QMediaCaptureSession *session);
124 QImageCapturePrivate *d_ptr;
125 Q_DISABLE_COPY(QImageCapture)
126 Q_DECLARE_PRIVATE(QImageCapture)
127 Q_PRIVATE_SLOT(d_func(), void _q_error(int, int, const QString &))
128};
129
130QT_END_NAMESPACE
131
132Q_MEDIA_ENUM_DEBUG(QImageCapture, Error)
133
134#endif
135
136

source code of qtmultimedia/src/multimedia/camera/qimagecapture.h