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
qohosimagecapture.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 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
8
9#include <QtCore/qdatetime.h>
10#include <QtGui/qimage.h>
11#include <QtMultimedia/qmediametadata.h>
12
14
16
18{
19 return m_session && m_session->isReadyForCapture();
20}
21
22int QOhosImageCapture::capture(const QString &fileName)
23{
24 if (!m_session) {
25 emit error(-1, QImageCapture::ResourceError, msgImageCaptureNotSet());
26 return -1;
27 }
28 return m_session->capture(fileName, /*toBuffer=*/false);
29}
30
32{
33 if (!m_session) {
34 emit error(-1, QImageCapture::ResourceError, msgImageCaptureNotSet());
35 return -1;
36 }
37 return m_session->capture(QString(), /*toBuffer=*/true);
38}
39
41{
42 if (m_session)
43 return m_session->imageSettings();
44 return m_pendingSettings;
45}
46
47void QOhosImageCapture::setImageSettings(const QImageEncoderSettings &settings)
48{
49 m_pendingSettings = settings;
50 if (m_session)
51 m_session->setImageSettings(settings);
52}
53
54void QOhosImageCapture::setCaptureSession(QPlatformMediaCaptureSession *session)
55{
56 auto *ohosSession = static_cast<QOhosMediaCaptureSession *>(session);
57 QOhosCameraSession *newCameraSession = ohosSession ? ohosSession->cameraSession() : nullptr;
58 if (m_service == ohosSession && m_session == newCameraSession)
59 return;
60
61 disconnectFromSession();
62 m_service = ohosSession;
63 m_session = newCameraSession;
64 if (m_session) {
65 m_session->setImageSettings(m_pendingSettings);
66 connectToSession();
67 notifyReadyForCaptureChanged(m_session->isReadyForCapture());
68 } else {
69 notifyReadyForCaptureChanged(false);
70 }
71}
72
73void QOhosImageCapture::notifyReadyForCaptureChanged(bool ready)
74{
75 if (m_lastReady == ready)
76 return;
77 m_lastReady = ready;
78 emit readyForCaptureChanged(ready);
79}
80
81void QOhosImageCapture::connectToSession()
82{
83 if (!m_session)
84 return;
85 connect(m_session, &QOhosCameraSession::readyForCaptureChanged, this,
86 &QOhosImageCapture::notifyReadyForCaptureChanged);
87 connect(m_session, &QOhosCameraSession::imageExposed, this, &QOhosImageCapture::imageExposed);
88 connect(m_session, &QOhosCameraSession::imageCaptured, this,
89 &QOhosImageCapture::onSessionImageCaptured);
90 connect(m_session, &QOhosCameraSession::imageAvailable, this,
91 &QOhosImageCapture::imageAvailable);
92 connect(m_session, &QOhosCameraSession::imageSaved, this, &QOhosImageCapture::imageSaved);
93 connect(m_session, &QOhosCameraSession::imageCaptureError, this, &QOhosImageCapture::error);
94}
95
96void QOhosImageCapture::onSessionImageCaptured(int id, const QImage &preview)
97{
98 emit imageCaptured(id, preview);
99
100 QMediaMetaData md = metaData();
101 md.insert(QMediaMetaData::Date, QDateTime::currentDateTime());
102 if (!preview.isNull())
103 md.insert(QMediaMetaData::Resolution, preview.size());
104 emit imageMetadataAvailable(id, md);
105}
106
107void QOhosImageCapture::disconnectFromSession()
108{
109 if (m_session)
110 disconnect(m_session, nullptr, this, nullptr);
111}
112
113QT_END_NAMESPACE
114
115#include "moc_qohosimagecapture_p.cpp"
\inmodule QtMultimedia
QObject * parent
Definition qobject.h:74
void imageExposed(int id)
void readyForCaptureChanged(bool ready)
int capture(const QString &fileName) override
bool isReadyForCapture() const override
void setCaptureSession(QPlatformMediaCaptureSession *session)
void setImageSettings(const QImageEncoderSettings &settings) override
QImageEncoderSettings imageSettings() const override
int captureToBuffer() override
Combined button and popup list for selecting options.