openharmony 鸿蒙 camera-macro

2026-08-25 浏览 (1)

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.

  1. Import the camera module, which provides camera-related properties and methods.

    import { camera } from '@kit.CameraKit';
    import { BusinessError } from '@kit.BasicServicesKit';
    
  2. Call isMacroSupported to check whether the current device supports macro photography.

    let isSupported: boolean = photoSession.isMacroSupported();
    
  3. 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-worker

openharmony 鸿蒙 camera-background-recovery

openharmony 鸿蒙 camera-preparation

openharmony 鸿蒙 camera-shooting

openharmony 鸿蒙 camera-moving-photo

openharmony 鸿蒙 camera-system-pressure

openharmony 鸿蒙 native-camera-preview-imageReceiver

openharmony 鸿蒙 native-camera-shooting

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/jEeztDH0