访问取景器帧,并拍摄照片和影片。 更多...
import 语句: | import QtMultimedia 5.15 |
继承: |
可以使用
Camera
to capture images and movies from a camera, and manipulate the capture and processing settings that get applied to the images. To display the viewfinder you can use
VideoOutput
with the Camera set as the source.
Item { width: 640 height: 360 Camera { id: camera imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash exposure { exposureCompensation: -1.0 exposureMode: Camera.ExposurePortrait } flash.mode: Camera.FlashRedEyeReduction imageCapture { onImageCaptured: { photoPreview.source = preview // Show the preview in an Image } } } VideoOutput { source: camera anchors.fill: parent focus : visible // to receive focus and capture key events when visible } Image { id: photoPreview } }
If multiple cameras are available, you can select which one to use by setting the deviceId property to a value from QtMultimedia.availableCameras . On a mobile device, you can conveniently switch between front-facing and back-facing cameras by setting the position 特性。
The various settings and functionality of the Camera stack is spread across a few different child properties of Camera.
特性 | 描述 |
---|---|
imageCapture | Methods and properties for capturing still images. |
videoRecorder | Methods and properties for capturing movies. |
exposure | Methods and properties for adjusting exposure (aperture, shutter speed etc). |
focus | Methods and properties for adjusting focus and providing feedback on autofocus progress. |
flash | Methods and properties for controlling the camera flash. |
imageProcessing | Methods and properties for adjusting camera image processing parameters. |
Basic camera state management, error reporting, and simple zoom properties are available in the Camera itself. For integration with C++ code, the mediaObject property allows you to access the standard Qt Multimedia camera controls.
Many of the camera settings may take some time to apply, and might be limited to certain supported values depending on the hardware. Some camera settings may be set manually or automatically. These settings properties contain the current set value. For example, when autofocus is enabled the focus zones are exposed in the focus 特性。
For additional information, read also the 摄像头概述 .
availability : enumeration |
This property holds the availability state of the camera.
常量 | 描述 |
---|---|
Camera.Available
|
The camera is available for use. |
Camera.Busy
|
The camera is busy at the moment as it is being used by another process. |
Camera.Unavailable
|
The camera is not available for use (there may be no camera hardware). |
Camera.ResourceMissing
|
The camera cannot be used because of missing resources. It may be possible to try again at a later time. |
cameraState : enumeration |
This property holds the camera object's current state. The default camera state is
ActiveState
.
常量 | 描述 |
---|---|
Camera.UnloadedState
|
The initial camera state, with the camera not loaded. The camera capabilities (with the exception of supported capture modes) are unknown. This state saves the most power, but takes the longest time to be ready for capture. While the supported settings are unknown in this state, you can still set the camera capture settings like codec, resolution, or frame rate. |
Camera.LoadedState
|
The camera is loaded and ready to be configured. In this state you can query camera capabilities, set capture resolution, codecs, and so on. The viewfinder is not active in the loaded state. The camera consumes power in this state. |
Camera.ActiveState
|
In the active state, the viewfinder frames are available and the camera is ready for capture. |
cameraStatus : enumeration |
This property holds the camera object's current status.
常量 | 描述 |
---|---|
Camera.ActiveStatus
|
The camera has been started and can produce data, viewfinder displays video frames. Depending on backend, changing camera settings such as capture mode, codecs, or resolution in
Camera.ActiveState
may lead to changing the status to
LoadedStatus
and
StartingStatus
while the settings are applied, and back to
ActiveStatus
when the camera is ready.
|
Camera.StartingStatus
|
The camera is transitioning to
Camera.ActiveState
. The camera service is not ready to capture yet.
|
Camera.StoppingStatus
|
The camera is transitioning from
Camera.ActiveState
to
Camera.LoadedState
or
Camera.UnloadedState
.
|
Camera.StandbyStatus
|
The camera is in the power saving standby mode. The camera may enter standby mode after some time of inactivity in the
Camera.LoadedState
状态。
|
Camera.LoadedStatus
|
The camera is loaded and ready to be configured. This status indicates that the camera is opened and it's possible to query for supported image and video capture settings, such as resolution, frame rate, and codecs. |
Camera.LoadingStatus
|
The camera is transitioning from
Camera.UnloadedState
to
Camera.LoadedState
or
Camera.ActiveState
.
|
Camera.UnloadingStatus
|
The camera is transitioning from
Camera.LoadedState
or
Camera.ActiveState
to
Camera.UnloadedState
.
|
Camera.UnloadedStatus
|
The initial camera status, with camera not loaded. The camera capabilities including supported capture settings may be unknown. |
Camera.UnavailableStatus
|
The camera or camera backend is not available. |
captureMode : enumeration |
This property holds the camera capture mode. The default capture mode is
CaptureStillImage
.
常量 | 描述 |
---|---|
Camera.CaptureViewfinder
|
Camera is only configured to display viewfinder. |
Camera.CaptureStillImage
|
Prepares the Camera for capturing still images. |
Camera.CaptureVideo
|
Prepares the Camera for capturing video. |
deviceId : string |
This property holds the unique identifier for the camera device being used. It may not be human-readable.
You can get all available device IDs from QtMultimedia.availableCameras . If no value is provided or if set to an empty string, the system's default camera will be used.
若可能的话, cameraState , captureMode , digitalZoom and other camera parameters are preserved when changing the camera device.
该特性在 Qt 5.4 引入。
另请参阅 displayName and position .
digitalZoom : real |
This property holds the current digital zoom factor.
[read-only] displayName : string |
This property holds the human-readable name of the camera.
You can use this property to display the name of the camera in a user interface.
该特性在 Qt 5.4 引入。
另请参阅 deviceId .
errorCode : enumeration |
此特性保持最后错误代码。
常量 | 描述 |
---|---|
Camera.NoError
|
没有出现错误。 |
Camera.CameraError
|
有出现错误。 |
Camera.InvalidRequestError
|
System resources do not support the requested functionality. |
Camera.ServiceMissingError
|
没有可用摄像头服务。 |
Camera.NotSupportedFeatureError
|
不支持特征。 |
另请参阅 errorOccurred and errorString .
errorString : string |
此特性保持最后错误字符串 (若有的话)。
另请参阅 errorOccurred and errorCode .
lockStatus : enumeration |
This property holds the status of all the requested camera locks.
常量 | 描述 |
---|---|
Camera.Unlocked
|
The application is not interested in camera settings value. The camera may keep this parameter without changes, which is common with camera focus, or adjust exposure and white balance constantly to keep the viewfinder image nice. |
Camera.Searching
|
The application has requested the camera focus, exposure, or white balance lock with searchAndLock() . This state indicates the camera is focusing or calculating exposure and white balance. |
Camera.Locked
|
The camera focus, exposure, or white balance is locked. The camera is ready to capture, and the application may check the exposure parameters. The locked state usually means the requested parameter stays the same, except in cases where the parameter is requested to be updated constantly. For example, in continuous focusing mode, the focus is considered locked as long as the object is in focus, even while the actual focusing distance may be constantly changing. |
maximumDigitalZoom : real |
This property holds the maximum digital zoom factor supported, or 1.0 if digital zoom is not supported.
maximumOpticalZoom : real |
This property holds the maximum optical zoom factor supported, or 1.0 if optical zoom is not supported.
mediaObject : variant |
This property holds the native media object for the camera.
It can be used to get a pointer to a QCamera object in order to integrate with C++ code.
QObject *qmlCamera; // The QML Camera object QCamera *camera = qvariant_cast<QCamera *>(qmlCamera->property("mediaObject"));
注意: This property is not accessible from QML.
metaData group |
---|
metaData.cameraManufacturer : variant |
metaData.cameraModel : variant |
metaData.dateTimeOriginal : variant |
metaData.event : variant |
metaData.gpsAltitude : variant |
metaData.gpsImgDirection : variant |
metaData.gpsLatitude : variant |
metaData.gpsLongitude : variant |
metaData.gpsProcessingMethod : variant |
metaData.gpsSpeed : variant |
metaData.gpsTimestamp : variant |
metaData.gpsTrack : variant |
metaData.orientation : variant |
metaData.subject : variant |
These properties hold the meta data for the camera captures.
metaData.cameraManufacturer
holds the name of the manufacturer of the camera.
metaData.cameraModel
holds the name of the model of the camera.
metaData.event
holds the event during which the photo or video is to be captured.
metaData.subject
holds the name of the subject of the capture or recording.
metaData.orientation
holds the clockwise rotation of the camera at time of capture.
metaData.dateTimeOriginal
holds the initial time at which the photo or video is captured.
metaData.gpsLatitude
holds the latitude of the camera in decimal degrees at time of capture.
metaData.gpsLongitude
holds the longitude of the camera in decimal degrees at time of capture.
metaData.gpsAltitude
holds the altitude of the camera in meters at time of capture.
metaData.gpsTimestamp
holds the timestamp of the GPS position data.
metaData.gpsTrack
holds direction of movement of the camera at the time of capture. It is measured in degrees clockwise from north.
metaData.gpsSpeed
holds the velocity in kilometers per hour of the camera at time of capture.
metaData.gpsImgDirection
holds direction the camera is facing at the time of capture. It is measured in degrees clockwise from north.
metaData.gpsProcessingMethod
holds the name of the method for determining the GPS position.
This QML property was introduced in Qt 5.4.
另请参阅 QMediaMetaData .
opticalZoom : real |
This property holds the current optical zoom factor.
[read-only] orientation : int |
This property holds the physical orientation of the camera sensor.
The value is the orientation angle (clockwise, in steps of 90 degrees) of the camera sensor in relation to the display in its natural orientation.
For example, suppose a mobile device which is naturally in portrait orientation. The back-facing camera is mounted in landscape. If the top side of the camera sensor is aligned with the right edge of the screen in natural orientation,
orientation
返回
270
. If the top side of a front-facing camera sensor is aligned with the right edge of the screen,
orientation
返回
90
.
该特性在 Qt 5.4 引入。
另请参阅 VideoOutput::orientation .
位置 : enumeration |
This property holds the physical position of the camera on the hardware system.
On a mobile device, this property can be used to easily choose between front-facing and back-facing cameras. If this property is set to
Camera.UnspecifiedPosition
, the system's default camera is used.
若可能的话, cameraState , captureMode , digitalZoom and other camera parameters are preserved when changing the camera device.
常量 | 描述 |
---|---|
Camera.UnspecifiedPosition
|
The camera position is unspecified or unknown. |
Camera.BackFace
|
The camera is on the back face of the system hardware. For example, on a mobile device, it is on side opposite from the screen. |
Camera.FrontFace
|
The camera is on the front face of the system hardware. For example, on a mobile device, it means it is on the same side as the screen. Viewfinder frames of front-facing cameras are mirrored horizontally, so the users can see themselves as looking into a mirror. Captured images or videos are not mirrored. |
该特性在 Qt 5.4 引入。
另请参阅 deviceId .
viewfinder group |
---|
viewfinder.maximumFrameRate : real |
viewfinder.minimumFrameRate : real |
viewfinder.resolution : size |
These properties hold the viewfinder settings.
viewfinder.resolution
holds the resolution of the camera viewfinder. If no resolution is given or if it is empty, the backend uses a default value.
viewfinder.minimumFrameRate
holds the minimum frame rate for the viewfinder in frames per second. If no value is given or if set to
0
, the backend uses a default value.
viewfinder.maximumFrameRate
holds the maximum frame rate for the viewfinder in frames per second. If no value is given or if set to
0
, the backend uses a default value.
若
viewfinder.minimumFrameRate
等于
viewfinder.maximumFrameRate
, the frame rate is fixed. If not, the actual frame rate fluctuates between the two values.
Changing the viewfinder settings while the camera is in the
Camera.ActiveState
state may cause the camera to be restarted.
If the camera is used to capture videos or images, the viewfinder settings might be ignored if they conflict with the capture settings. You can check the actual viewfinder settings once the camera is in the
Camera.ActiveStatus
状态。
Supported values can be retrieved with supportedViewfinderResolutions() and supportedViewfinderFrameRateRanges() .
This QML property was introduced in Qt 5.4.
This signal is emitted when the camera state has changed to state . Since the state changes may take some time to occur this signal may arrive sometime after the state change has been requested.
相应处理程序是
onCameraStateChanged
.
注意:
相应处理程序是
onCameraStateChanged
.
This signal is emitted when the digital zoom setting has changed to zoom .
相应处理程序是
onDigitalZoomChanged
.
注意:
相应处理程序是
onDigitalZoomChanged
.
This signal is emitted when an error specified by errorCode occurs. A descriptive string value is available in errorString .
相应处理程序是
onError
.
注意:
相应处理程序是
onErrorOccurred
.
This signal was introduced in Qt 5.15.
另请参阅 errorCode and errorString .
This signal is emitted when the lock status (focus, exposure etc) changes. This can happen when locking (e.g. autofocusing) is complete or has failed.
相应处理程序是
onLockStatusChanged
.
注意:
相应处理程序是
onLockStatusChanged
.
此信号发射当
manualWhiteBalance
特性改变。
相应处理程序是
onManualWhiteBalanceChanged
.
注意:
相应处理程序是
onManualWhiteBalanceChanged
.
This signal is emitted when the maximum digital zoom setting has changed to zoom . This can occur when you change between video and still image capture modes, or the capture settings are changed.
相应处理程序是
onMaximumDigitalZoomChanged
.
注意:
相应处理程序是
onMaximumDigitalZoomChanged
.
This signal is emitted when the maximum optical zoom setting has changed to zoom . This can occur when you change between video and still image capture modes, or the capture settings are changed.
相应处理程序是
onMaximumOpticalZoomChanged
.
注意:
相应处理程序是
onMaximumOpticalZoomChanged
.
This signal is emitted when the optical zoom setting has changed to zoom .
相应处理程序是
onOpticalZoomChanged
.
注意:
相应处理程序是
onOpticalZoomChanged
.
此信号发射当
whiteBalanceMode
特性改变。
相应处理程序是
onWhiteBalanceModeChanged
.
注意:
相应处理程序是
onWhiteBalanceModeChanged
.
Start focusing, exposure and white balance calculation.
This is appropriate to call when the camera focus button is pressed (or on a camera capture button half-press). If the camera supports autofocusing, information on the focus zones is available through the focus 特性。
Starts the camera. Viewfinder frames will be available and image or movie capture will be possible.
Stops the camera, but leaves the camera stack loaded.
In this state, the camera still consumes power.
list < 对象 > supportedViewfinderFrameRateRanges ( size resolution ) |
Returns a list of supported viewfinder frame rate ranges.
Each range object in the list has the
minimumFrameRate
and
maximumFrameRate
特性。
If the optional parameter resolution is specified, the returned list is reduced to frame rate ranges supported for the given resolution .
The camera must be loaded before calling this function, otherwise the returned list is empty.
该方法在 Qt 5.5 引入。
另请参阅 viewfinder .
list < size > supportedViewfinderResolutions ( real minimumFrameRate , real maximumFrameRate ) |
Returns a list of supported viewfinder resolutions.
If both optional parameters minimumFrameRate and maximumFrameRate are specified, the returned list is reduced to resolutions supported for the given frame rate range.
The camera must be loaded before calling this function, otherwise the returned list is empty.
该方法在 Qt 5.5 引入。
另请参阅 viewfinder .
Unlock focus, exposure and white balance locks.