QCameraDevice Class
QCameraDevice 类提供有关相机设备的一般信息。更多
头文件: | #include <QCameraDevice> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Multimedia) target_link_libraries(mytarget PRIVATE Qt6::Multimedia) |
qmake: | QT += multimedia |
公共类型
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 实例。
本例将打印所有可用摄像机的名称:
常量QList<QCameraDevice> 摄像机=QMediaDevices::videoInputs();for(constQCameraDevice摄像机设备: 摄像机) 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 获取摄像机设备的一般信息,如描述和在系统中的物理位置。
QCameramyCamera;QCameraDevicecameraDevice=camera->cameraDevice();如果(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::UnspecifiedPosition | 0 | 摄像机位置未指定或未知。 |
QCameraDevice::BackFace | 1 | 摄像头位于系统硬件的背面。例如,在移动设备上,这意味着摄像头位于屏幕的反面。 |
QCameraDevice::FrontFace | 2 | 摄像头位于系统硬件的正面。例如,在移动设备上,这意味着它与屏幕在同一面。前置摄像头生成的视频帧的属性QVideoFrame::mirrored 设置为true 。这意味着这些帧的显示方式会围绕纵轴翻转,以镜像方式显示视频输出,而录制时只考虑QVideoFrame::surfaceFormat 中指定的表面变换。 |
另请参阅 position() 。
属性文档
[read-only, since 6.7]
correctionAngle : const QtVideo::Rotation
返回补偿相机物理旋转所需的旋转角度。换句话说,该属性表示输出图像需要旋转的顺时针角度,以便以原始方向直立显示在设备屏幕上。由于correctionAngle 是相对于本机方向而言的,因此该值不会随设备方向(纵向/横向)的改变而改变。在 Android 系统中,校正角度可能不为零,因为本机方向和相机方向是由制造商定义的。
此属性在 Qt 6.7 中引入。
访问函数:
QtVideo::Rotation | correctionAngle() const |
[read-only]
description : const QString
返回摄像机的人可读描述。
使用此字符串向用户展示设备。
访问功能:
QString | description() const |
[read-only]
id : const QByteArray
返回摄像机的设备 ID
这是一个用于识别摄像机的唯一 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()
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。
© 2025 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.