ImageCapture QML Type
捕捉相机图像的接口。更多
Import Statement: | import QtMultimedia |
属性
- error : enumeration
- errorString : string
- fileFormat : enumeration
- metaData : mediaMetaData
- preview : string
- quality : enumeration
- readyForCapture : bool
- supportedFormats : list<FileFormat>
(since 6.10)
信号
- errorOccurred(id, error, errorString)
- imageCaptured(requestId, preview)
- imageMetadataAvailable(id, metaData)
- imageSaved(id, fileName)
方法
- capture()
- captureToFile(location)
- saveToFile(location)
详细说明
该类型允许您捕捉静态图像,并在图像可用或保存到磁盘时收到通知。
Item { width: 640 height: 360 CaptureSession { imageCapture : ImageCapture { id: imageCapture } camera: Camera { id: camera } videoOutput: videoOutput } VideoOutput { id: videoOutput anchors.fill: parent MouseArea { anchors.fill: parent; onClicked: imageCapture.capture(); } } Image { id: photoPreview source: imageCapture.preview // always shows the last captured image } }
属性文档
error : enumeration |
该属性包含最后发生的错误类型。它可以是以下类型之一。
常量 | 说明 |
---|---|
ImageCapture.NoError | 无错误。 |
ImageCapture.NotReadyError | 服务尚未准备好捕获。 |
ImageCapture.ResourceError | 设备未就绪或不可用。 |
ImageCapture.OutOfSpaceError | 设备无剩余空间。 |
ImageCapture.NotSupportedFeatureError | 设备不支持静态图像捕捉。 |
ImageCapture.FormatError | 不支持当前格式。 |
另请参阅 errorString 。
fileFormat : enumeration |
此属性保存将写入图像的文件格式。可以是以下格式之一。
常量 | 说明 |
---|---|
UnspecifiedFormat | 未指定格式 |
JPEG | .jpg 或.jpeg 格式 |
PNG | .png 格式 |
WebP | .webp 格式 |
Tiff | .tiff 格式 |
metaData : mediaMetaData |
此属性包含将嵌入图像的元数据。
preview : string |
该属性包含最新捕获图像的 URL。它可以连接到Image 元素的源属性,以显示最后捕获的图像。
CaptureSession { camera: Camera {} imageCapture: ImageCapture { id: capture } } Image { source: capture.preview }
另请参阅 saveToFile 。
quality : enumeration |
该属性用于保存捕获图像时的质量提示。它可以是以下值之一。
常量 | 说明 |
---|---|
VeryLowQuality | 极低 |
LowQuality | 低 |
NormalQuality | 正常 |
HighQuality | 高 |
VeryHighQuality | 非常高 |
readyForCapture : bool |
此属性包含一个 bool 值,表示摄像机是否已准备好拍摄照片。
在就绪状态为false
时调用capture() 或captureToFile() 是不允许的,会导致错误。
supportedFormats : list<FileFormat> |
信号文档
errorOccurred(id, error, errorString) |
id error 是一个 ImageCapture::Error 类型的枚举。描述性信息见 。errorString
注: 相应的处理程序是onErrorOccurred
。
另请参阅 error 和errorString 。
imageCaptured(requestId, preview) |
当已捕获请求 id 为requestId 的图像但尚未保存到文件系统时,将发出此信号。preview 参数为捕获的图像。
注: 相应的处理程序是onImageCaptured
。
另请参阅 imageSaved 和preview 。
imageMetadataAvailable(id, metaData) |
imageSaved(id, fileName) |
方法文档
capture() |
开始图像捕捉。捕获完成后,将发出imageCaptured 和imageSaved 信号。
捕获的图像将通过预览属性提供,可用作 QML 图像项的源。然后可使用saveToFile() 方法保存图像。
相机会保存所有捕捉参数,如曝光设置或图像处理参数,因此调用 capture() 后更改相机参数不会影响之前的捕捉请求。
capture()会返回捕捉请求 ID 参数,与 imageExposed()、imageCaptured( )、imageMetadataAvailable() 和imageSaved() 信号一起使用。
另请参阅 readyForCapture 和preview 。
© 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.