QCameraDevice Class

The QCameraDevice class provides general information about camera devices. 更多...

頭: #include <QCameraDevice>
CMake: find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia
在 QML: cameraDevice

公共類型

enum Position { UnspecifiedPosition, BackFace, FrontFace }

特性

公共函數

QCameraDevice ()
QCameraDevice (const QCameraDevice & other )
~QCameraDevice ()
QtVideo::Rotation correctionAngle () const
QString description () const
QByteArray id () const
bool isDefault () const
bool isNull () const
QList<QSize> photoResolutions () const
QCameraDevice::Position position () const
QList<QCameraFormat> videoFormats () const
bool operator!= (const QCameraDevice & other ) const
QCameraDevice & operator= (const QCameraDevice & other )
bool operator== (const QCameraDevice & other ) const

詳細描述

QCameraDevice represents a physical camera device and its properties.

You can discover what cameras are available on a system using the availableCameras() and defaultCamera() functions. These are contained within QtMultimedia::MediaDevices.

The QCameraDevice instance retains its properties throughout its lifetime, even if the corresponding physical device is disconnected or its settings are modified. To keep track of updated properties, the user should load new instances of QCameraDevice from QMediaDevices when the relevant signals are fired.

This example prints the name of all available cameras:

const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
for (const QCameraDevice &cameraDevice : cameras)
    qDebug() << cameraDevice.description();
					

A QCameraDevice can be used to construct a QCamera . The following example instantiates a QCamera whose camera device is named mycamera :

const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
for (const QCameraDevice &cameraDevice : cameras) {
    if (cameraDevice.description() == "mycamera")
        camera = new QCamera(cameraDevice);
}
					

You can also use QCameraDevice to get general information about a camera device such as description and physical position on the system.

QCamera myCamera;
QCameraDevice cameraDevice = camera->cameraDevice();
if (cameraDevice.position() == QCameraDevice::FrontFace)
    qDebug() << "The camera is on the front face of the hardware system.";
else if (cameraDevice.position() == QCameraDevice::BackFace)
    qDebug() << "The camera is on the back face of the hardware system.";
					

另請參閱 QCamera .

成員類型文檔編製

enum QCameraDevice:: Position

This enum specifies the physical position of the camera on the system hardware.

常量 描述
QCameraDevice::UnspecifiedPosition 0 The camera position is unspecified or unknown.
QCameraDevice::BackFace 1 The camera is on the back face of the system hardware. For example on a mobile device, it means it is on the opposite side to that of the screen.
QCameraDevice::FrontFace 2 The camera is on the front face of the system hardware. For example on a mobile device, it means it is on the same side as that of the screen. Front-facing cameras generate video frames with the property QVideoFrame::mirrored 設為 true . This means that the presentation of these frames is flipped around the vertical axis to display the video output as a mirror, whereas recording only considers the transformations of the surface specified in QVideoFrame::surfaceFormat .

另請參閱 position ().

特性文檔編製

[read-only, since 6.7] correctionAngle : const QtVideo::Rotation

Returns the rotation angle needed to compensate for the physical camera rotation of the camera compared to its native orientation. In other words, the property represents the clockwise angle through which the output image needs to be rotated to be upright on the device screen in its native orientation. Since correctionAngle is relative to the native orientation, this value does not change with altering the device orientation (portrait/landscape). The correction angle may be non-zero mostly on Android, where native and camera orientations are defined by the manufacturer.

Example with 90 degrees \a correctionAngle

該特性在 Qt 6.7 引入。

訪問函數:

QtVideo::Rotation correctionAngle () const

[read-only] description : const QString

Returns the human-readable description of the camera.

Use this string to present the device to the user.

訪問函數:

QString 描述 () const

[read-only] id : const QByteArray

Returns the device id of the camera

This is a unique ID to identify the camera and may not be human-readable.

訪問函數:

QByteArray id () const

[read-only] isDefault : const bool

Returns true if this is the default camera device.

訪問函數:

bool isDefault () const

[read-only] 位置 : const Position

Returns the physical position of the camera on the hardware system.

訪問函數:

QCameraDevice::Position 位置 () const

[read-only] videoFormats : const QList < QCameraFormat >

Returns the video formats supported by the camera.

訪問函數:

QList<QCameraFormat> videoFormats () const

成員函數文檔編製

QCameraDevice:: QCameraDevice ()

Constructs a null camera device

QCameraDevice:: QCameraDevice (const QCameraDevice & other )

構造副本為 other .

[noexcept] QCameraDevice:: ~QCameraDevice ()

銷毀 QCameraDevice .

bool QCameraDevice:: isNull () const

返迴 true,若此 QCameraDevice is null or invalid.

QList < QSize > QCameraDevice:: photoResolutions () const

Returns a list of resolutions that the camera can use to capture still images.

另請參閱 QImageCapture .

bool QCameraDevice:: operator!= (const QCameraDevice & other ) const

返迴 true,若此 QCameraDevice does not represent the same device as other .

QCameraDevice &QCameraDevice:: operator= (const QCameraDevice & other )

設置 QCameraDevice 對象等於 other .

bool QCameraDevice:: operator== (const QCameraDevice & other ) const

返迴 true,若此 QCameraDevice represents the same device as other .

Due to the behavior of the properties in QCameraDevice , two QCameraDevice instances can be considered equal even if not all the properties are equal.