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)
方法
- int capture()
- int captureToFile(location)
- void 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 [read-only]
该属性包含最后发生的错误类型。它可以是以下类型之一。
| 常量 | 说明 |
|---|---|
ImageCapture.NoError | 无错误。 |
ImageCapture.NotReadyError | 服务尚未准备好捕获。 |
ImageCapture.ResourceError | 设备未就绪或不可用。 |
ImageCapture.OutOfSpaceError | 设备无剩余空间。 |
ImageCapture.NotSupportedFeatureError | 设备不支持静态图像捕捉。 |
ImageCapture.FormatError | 不支持当前格式。 |
另请参阅 errorString 。
errorString : string [read-only]
该属性包含最后出现的错误信息。
另请参见 error 。
fileFormat : enumeration
此属性用于保存写入图像的文件格式。可以是以下格式之一。
| 常量 | 说明 |
|---|---|
UnspecifiedFormat | 未指定格式 |
JPEG | .jpg 或.jpeg 格式 |
PNG | .png 格式 |
WebP | .webp 格式 |
Tiff | .tiff 格式 |
metaData : mediaMetaData
该属性包含将嵌入图像的元数据。
preview : string [read-only]
该属性包含最新捕获图像的 URL。它可以连接到Image 元素的源属性,以显示最后捕获的图像。
CaptureSession {
camera: Camera {}
imageCapture: ImageCapture {
id: capture
}
}
Image {
source: capture.preview
}另请参阅 saveToFile 。
quality : enumeration
该属性用于保存捕获图像时的质量提示。它可以是以下值之一。
| 常数 | 说明 |
|---|---|
VeryLowQuality | 极低 |
LowQuality | 低 |
NormalQuality | 正常 |
HighQuality | 高 |
VeryHighQuality | 非常高 |
readyForCapture : bool [read-only]
此属性包含一个 bool 值,表示摄像机是否已准备好拍摄照片。
在就绪状态为false 时调用capture() 或captureToFile() 是不允许的,会导致错误。
supportedFormats : list<FileFormat> [read-only, since 6.10]
包含支持的文件格式列表。
此属性在 Qt 6.10 中引入。
另请参阅 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)
当请求id 的图像有新的metaData 时,会发出该信号。
注: 相应的处理程序是onImageMetadataAvailable 。
另请参阅 imageCaptured 。
imageSaved(id, fileName)
请求id 的图像写入文件系统后发出此信号。fileName 是本地文件路径,而不是 URL。
注意: 相应的处理程序是onImageSaved 。
另请参阅 imageCaptured 。
方法文档
int capture()
开始图像捕捉。捕捉完成后,将发出imageCaptured 和imageSaved 信号。
捕获的图像将通过预览属性提供,该属性可用作 QML 图像项的源。然后可使用saveToFile() 方法保存图像。
相机会保存所有捕捉参数,如曝光设置或图像处理参数,因此调用 capture() 后更改相机参数不会影响之前的捕捉请求。
capture()返回捕捉请求 ID 参数,与 imageExposed()、imageCaptured( )、imageMetadataAvailable() 和imageSaved() 信号一起使用。
另请参阅 readyForCapture 和preview 。
int captureToFile(location)
功能与capture() 相同,但会自动将捕获的图像保存到指定的location 。返回捕获 requestId 参数。
另请参阅 capture()。
void saveToFile(location)
将最后捕获的图像保存到location 。
© 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.