本页内容

ImageCapture QML Type

用于捕获摄像头图像的接口。更多...

Import Statement: import QtMultimedia

属性

信号

方法

详细说明

此类允许您捕获静止图像,并在图像可用或保存到磁盘时收到通知。

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 ` 元素的 `source` 属性关联,以显示最后捕获的图像。

CaptureSession {
    camera: Camera {}
    imageCapture: ImageCapture {
        id: capture
    }
}
Image {
    source: capture.preview
}

另请参阅 saveToFile 。

quality : enumeration

该属性在存储捕获的图像时保留画质提示。其值可以是以下选项之一。

常量描述
VeryLowQuality非常低
LowQuality低
NormalQuality正常
HighQuality高
VeryHighQuality极高

readyForCapture : bool [read-only]

该属性保存一个布尔值,用于指示相机是否已准备好拍摄照片。

当相机处于就绪状态时,若调用capture()或captureToFile(),且false 为false,则该操作不被允许,并将引发错误。

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 信号。

捕获的图像可通过 preview 属性获取,该属性可作为 QML Image 项的来源。随后可使用saveToFile() 方法保存图像。

相机会保存所有捕获参数(如曝光设置或图像处理参数),因此调用 `capture()` 之后对相机参数所做的更改不会影响之前的捕获请求。

capture() 返回捕获请求 ID 参数,该参数用于配合 imageExposed()、imageCaptured()、imageMetadataAvailable() 和imageSaved() 信号使用。

另请参阅 readyForCapture 和preview 。

int captureToFile(location)

其功能与capture() 相同,但会额外将捕获的图像自动保存到指定的location 。返回捕获请求 ID(requestId)参数。

另请参阅 capture()。

void saveToFile(location)

将最后捕获的图像保存到location 。

另请参阅 capture 和preview 。

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