Macro Photography Settings (ArkTS)
Starting from API version 19, you can configure macro photography. This feature allows the camera to focus closely and capture detailed images of small objects through optimized optical design and algorithms.
How to Develop
Read Camera for the API reference.
-
Import the camera module, which provides camera-related properties and methods.
import { camera } from '@kit.CameraKit'; import { BusinessError } from '@kit.BasicServicesKit'; -
Call isMacroSupported to check whether the current device supports macro photography.
let isSupported: boolean = photoSession.isMacroSupported(); -
Call enableMacro to enable or disable macro photography.
function EnableMacro(photoSession: camera.PhotoSession): void { let isSupported: boolean = photoSession.isMacroSupported(); if (isSupported) { photoSession.enableMacro(true); } }
Status Listening
Starting from API version 20, you can listen for macro photography status changes.
Call on('macroStatusChanged') to listen for the macroStatusChanged event to track changes in macro photography.
function callback(err: BusinessError, macroStatus: boolean): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`Macro state: ${macroStatus}`);
}
// Register a callback.
function registerMacroStatusChanged(photoSession: camera.PhotoSession): void {
photoSession.on('macroStatusChanged', callback);
}
// Stop the listening.
function unregisterMacroStatusChanged(photoSession: camera.PhotoSession): void {
photoSession.off('macroStatusChanged');
}
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 camera-whitebalance
openharmony 鸿蒙 native-camera-preview
openharmony 鸿蒙 camera-background-recovery
openharmony 鸿蒙 camera-preparation
openharmony 鸿蒙 camera-shooting
openharmony 鸿蒙 camera-moving-photo
openharmony 鸿蒙 camera-system-pressure