QImageCapture Class

The QImageCapture class is used for the recording of media content. More...

Header: #include <QImageCapture>
CMake: find_package(Qt6 COMPONENTS Multimedia REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia
Inherits: QObject

Public Types

enum Error { NoError, NotReadyError, ResourceError, OutOfSpaceError, NotSupportedFeatureError, FormatError }
enum Quality { VeryLowQuality, LowQuality, NormalQuality, HighQuality, VeryHighQuality }


Public Functions

QImageCapture(QObject *parent = nullptr)
virtual ~QImageCapture()
void addMetaData(const QMediaMetaData &metaData)
QMediaCaptureSession *captureSession() const
QImageCapture::Error error() const
QString errorString() const
QImageCapture::FileFormat fileFormat() const
bool isAvailable() const
bool isReadyForCapture() const
QMediaMetaData metaData() const
QImageCapture::Quality quality() const
QSize resolution() const
void setFileFormat(QImageCapture::FileFormat format)
void setMetaData(const QMediaMetaData &metaData)
void setQuality(QImageCapture::Quality quality)
void setResolution(const QSize &resolution)
void setResolution(int width, int height)

Public Slots

int capture()
int captureToFile(const QString &file = QString())


void errorChanged()
void errorOccurred(int id, QImageCapture::Error error, const QString &errorString)
void fileFormatChanged()
void imageAvailable(int id, const QVideoFrame &frame)
void imageCaptured(int id, const QImage &preview)
void imageExposed(int id)
void imageSaved(int id, const QString &fileName)
void metaDataChanged()
void qualityChanged()
void readyForCaptureChanged(bool ready)

Detailed Description

The QImageCapture class is a high level images recording class. It's not intended to be used alone but for accessing the media recording functions of other media objects, like QCamera.

QMediaCaptureSession captureSession;
camera = new QCamera;

QVideoWidget *preview = new QVideoWidget();

imageCapture = new QImageCapture(camera);

//on shutter button pressed

See also QCamera.

Member Type Documentation

enum QImageCapture::Error

QImageCapture::NoError0No Errors.
QImageCapture::NotReadyError1The service is not ready for capture yet.
QImageCapture::ResourceError2Device is not ready or not available.
QImageCapture::OutOfSpaceError3No space left on device.
QImageCapture::NotSupportedFeatureError4Device does not support stillimages capture.
QImageCapture::FormatError5Current format is not supported.

enum QImageCapture::Quality

Enumerates quality encoding levels.


Property Documentation

[read-only] fileFormat : const FileFormat

This property holds the image format.

Access functions:

QImageCapture::FileFormat fileFormat() const

Notifier signal:

void fileFormatChanged()

metaData : QMediaMetaData

This property holds the meta data that will get embedded into the image.

Note: Additional fields such as a time stamp or location may get added by the camera back end.

Access functions:

QMediaMetaData metaData() const
void setMetaData(const QMediaMetaData &metaData)

Notifier signal:

void metaDataChanged()

[read-only] quality : const Quality

This property holds the image encoding quality.

Access functions:

QImageCapture::Quality quality() const

Notifier signal:

void qualityChanged()

[read-only] readyForCapture : const bool

Holds true if the camera is ready to capture an image immediately. Calling capture() while readyForCapture is false is not permitted and results in an error.

Access functions:

bool isReadyForCapture() const

Notifier signal:

void readyForCaptureChanged(bool ready)

Member Function Documentation

QImageCapture::QImageCapture(QObject *parent = nullptr)

Constructs a image capture object, from a parent, that can capture individual still images produced by a camera.

You must connect both an image capture object and a QCamera to a capture session to capture images.

[slot] int QImageCapture::capture()

Capture the image and make it available as a QImage. This operation is asynchronous in majority of cases, followed by signals QImageCapture::imageExposed(), QImageCapture::imageCaptured() or QImageCapture::error().

QImageCapture::capture returns the capture Id parameter, used with imageExposed(), imageCaptured() and imageSaved() signals.

See also isReadyForCapture().

[slot] int QImageCapture::captureToFile(const QString &file = QString())

Capture the image and save it to file. This operation is asynchronous in majority of cases, followed by signals QImageCapture::imageExposed(), QImageCapture::imageCaptured(), QImageCapture::imageSaved() or QImageCapture::error().

If an empty file is passed, the camera back end chooses the default location and naming scheme for photos on the system, if only file name without full path is specified, the image will be saved to the default directory, with a full path reported with imageCaptured() and imageSaved() signals.

QCamera saves all the capture parameters like exposure settings or image processing parameters, so changes to camera parameters after capture() is called do not affect previous capture requests.

QImageCapture::capture returns the capture Id parameter, used with imageExposed(), imageCaptured() and imageSaved() signals.

See also isReadyForCapture().

[signal] void QImageCapture::errorOccurred(int id, QImageCapture::Error error, const QString &errorString)

Signals that the capture request id has failed with an error and errorString description.

[signal] void QImageCapture::imageAvailable(int id, const QVideoFrame &frame)

Signal emitted when QImageCapture::CaptureToBuffer is set and the frame with request id is available.

[signal] void QImageCapture::imageCaptured(int id, const QImage &preview)

Signal emitted when the frame with request id was captured, but not processed and saved yet. Frame preview can be displayed to user.

[signal] void QImageCapture::imageExposed(int id)

Signal emitted when the frame with request id was exposed.

[signal] void QImageCapture::imageSaved(int id, const QString &fileName)

Signal emitted when QImageCapture::CaptureToFile is set and the frame with request id was saved to fileName.

[signal] void QImageCapture::readyForCaptureChanged(bool ready)

Signals that a camera's ready for capture state has changed.

Note: Notifier signal for property readyForCapture.

[virtual] QImageCapture::~QImageCapture()

Destroys images capture object.

void QImageCapture::addMetaData(const QMediaMetaData &metaData)

Adds additional metaData to any existing meta data, that is embedded into the captured image.

QMediaCaptureSession *QImageCapture::captureSession() const

Returns the capture session this camera is connected to, or a nullptr if the camera is not connected to a capture session.

Use QMediaCaptureSession::setImageCapture() to connect the image capture to a session.

QImageCapture::Error QImageCapture::error() const

Returns the current error state.

Note: Getter function for property error.

See also errorString().

QString QImageCapture::errorString() const

Returns a string describing the current error state.

Note: Getter function for property errorString.

See also error().

bool QImageCapture::isAvailable() const

Returns true if the images capture service ready to use.

QSize QImageCapture::resolution() const

Returns the resolution of the encoded image.

See also setResolution().

void QImageCapture::setFileFormat(QImageCapture::FileFormat format)

Sets the image format.

See also fileFormat().

void QImageCapture::setMetaData(const QMediaMetaData &metaData)

Replaces any existing meta data, to be embedded into the captured image, with a set of metaData.

Note: Setter function for property metaData.

See also metaData().

void QImageCapture::setQuality(QImageCapture::Quality quality)

Sets the image encoding quality.

See also quality().

void QImageCapture::setResolution(const QSize &resolution)

Sets the resolution of the encoded image.

An empty QSize indicates the encoder should make an optimal choice based on what is available from the image source and the limitations of the codec.

See also resolution().

void QImageCapture::setResolution(int width, int height)

Sets the width and height of the resolution of the encoded image.

This is an overloaded function.

© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.