Interface (ZoomQuery)
ZoomQuery provides APIs to query the zoom feature of a device camera, including the API to obtain the supported zoom ratio range.
NOTE
- The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
- This interface was first introduced in API version 12. In this version, a compatibility change was made that preserved the initial version information of inner elements. As a result, you might see outer element's @since version number being higher than that of the inner elements. However, this discrepancy does not affect the functionality of the interface.
Modules to Import
import { camera } from '@kit.CameraKit';
getZoomRatioRange11+
getZoomRatioRange(): Array<number>
Obtains the supported zoom ratio range.
Atomic service API: This API can be used in atomic services since API version 19.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
| Type | Description |
|---|---|
| Array<number> | Array containing the minimum and maximum zoom ratios. If the operation fails, undefined is returned and an error code defined in CameraErrorCode is thrown. If the device does not support zoom, undefined is returned when this API is called. |
Error codes
For details about the error codes, see Camera Error Codes.
| ID | Error Message |
|---|---|
| 7400103 | Session not config, only throw in session usage. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
function getZoomRatioRange(photoSession: camera.PhotoSession): Array<number> {
let zoomRatioRange: Array<number> = [];
try {
zoomRatioRange = photoSession.getZoomRatioRange();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
}
return zoomRatioRange;
}
getRAWCaptureZoomRatioRange24+
getRAWCaptureZoomRatioRange(): Array<number>
Obtains the supported zoom ratio range during shooting in RAW format.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 24.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
| Type | Description |
|---|---|
| Array<number> | Zoom ratio range. |
Error codes
For details about the error codes, see Camera Error Codes.
| ID | Error Message |
|---|---|
| 7400102 | Operation not allowed, the inputDevice or the session is abnormal. |
| 7400103 | Session not config. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
function getRAWCaptureZoomRatioRange(photoSession: camera.PhotoSession): Array<number> {
let zoomRatioRange: Array<number> = [];
try {
zoomRatioRange = photoSession.getRAWCaptureZoomRatioRange();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getRAWCaptureZoomRatioRange call failed. error code: ${err.code}`);
}
return zoomRatioRange;
}