本页内容

QCameraDevice Class

QCameraDevice 类提供了有关摄像头设备的一般信息。更多内容...

头文件: #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 代表一个物理摄像头设备及其属性。

您可以使用 availableCameras() 和 defaultCamera() 函数来检测系统上可用的摄像头。这些函数包含在 QtMultimedia::MediaDevices 中。

QCameraDevice 实例在其生命周期内始终保留其属性,即使相应的物理设备已断开连接或其设置已被修改。为了跟踪更新的属性,用户应在相关信号触发时,从 `QMediaDevices ` 加载新的 QCameraDevice 实例。

本示例打印所有可用摄像头的名称:

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

可以使用 QCameraDevice 来创建一个QCamera 。以下示例实例化了一个QCamera ,其相机设备名为mycamera :

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

您还可以使用 QCameraDevice 获取相机设备的通用信息,例如描述以及在系统中的物理位置。

QCamera myCamera;
QCameraDevice cameraDevice=myCamera.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

此枚举指定了摄像头在系统硬件上的物理位置。

常量值描述
QCameraDevice::UnspecifiedPosition0相机位置未指定或未知。
QCameraDevice::BackFace1摄像头位于系统硬件的背面。例如,在移动设备上,这意味着它位于与屏幕相对的一侧。
QCameraDevice::FrontFace2摄像头位于系统硬件的正面。例如在移动设备上,这意味着它位于与屏幕同一侧。 前置摄像头生成的视频帧其QVideoFrame::mirrored 属性设置为true 。这意味着这些帧的呈现会围绕垂直轴翻转,以镜像形式显示视频输出,而录制时仅考虑QVideoFrame::surfaceFormat 中指定的表面变换。

另请参阅 position()。

属性文档

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

返回用于补偿相机相对于其原生方向的物理旋转所需的旋转角度。换言之,该属性表示输出图像需要顺时针旋转的角,以便在设备屏幕上以原生方向正确显示。 由于 `correctionAngle ` 是相对于原生方向的,因此该值不会因设备方向(纵向/横向)的改变而变化。在 Android 系统中,校正角度通常可能不为零,因为原生方向和相机方向由制造商定义。

以90度\a为校正角的示例

该枚举类型在 Qt 6.7 中引入。

访问函数:

QtVideo::Rotation correctionAngle() const

[read-only] description : const QString

返回相机的通俗描述。

使用此字符串向用户展示该设备。

访问函数:

QString description() const

[read-only] id : const QByteArray

返回摄像头的设备 ID

这是一个用于识别相机的唯一标识符,可能无法被人类直接识别。

访问函数:

QByteArray id() const

[read-only] isDefault : const bool

如果这是默认摄像头设备,则返回 true。

访问函数:

bool isDefault() const

[read-only] position : const Position

返回相机在硬件系统上的物理位置。

访问函数:

QCameraDevice::Position position() const

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

返回相机支持的视频格式。

访问函数:

QList<QCameraFormat> videoFormats() const

成员函数文档

QCameraDevice::QCameraDevice()

创建一个空相机设备

QCameraDevice::QCameraDevice(const QCameraDevice &other)

创建other 的副本。

[noexcept] QCameraDevice::~QCameraDevice()

销毁QCameraDevice 。

bool QCameraDevice::isNull() const

如果该QCameraDevice 为空或无效,则返回true。

QList<QSize> QCameraDevice::photoResolutions() const

返回相机可用于拍摄静态图像的分辨率列表。

另请参阅 QImageCapture 。

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

如果此QCameraDevice 所表示的设备与other 所表示的设备不一致,则返回true。

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

将QCameraDevice 对象设置为与other 相同。

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

如果该QCameraDevice 与other 表示的是同一台设备,则返回true。

由于QCameraDevice 中属性的行为特性,即使并非所有属性都相同,两个QCameraDevice 实例仍可能被视为相等。

© 2026 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.