openharmony 鸿蒙 js-apis-awareness-metadataBinding-sys

2025-06-12 浏览 (1)

@ohos.multimodalAwareness.metadataBinding (Metadata Binding)

The metadataBinding module provides the capability of adding metadata to images and parsing the metadata to complete information transfer.

NOTE

The initial APIs of this module are supported since API version 18. Newly added APIs will be marked with a superscript to indicate their earliest API version.

The APIs provided by this module are system APIs.

Modules to Import

import { metadataBinding } from '@kit.MultimodalAwarenessKit';

encodeImage(image.PixelMap, string)

encodeImage(srcImage: image.PixelMap, metadata: string): Promise<image.PixelMap>;
Encodes metadata into an image. System capability: SystemCapability.MultimodalAwareness.metadataBinding System API: This is a system API.

Parameters

NameTypeMandatoryDescription
srcImagePixelMapYesSource image.
metadatastringYesMetadata to encoded.
PromisePromise<image.PixelMap>YesCallback used to return the image with encoded metadata.

Error codes

For details about the error codes, see Metadata Binding Error Codes and Universal Error Codes.

IDError Message
202Permission check failed. A non-system application uses the system API.
32100001Internal handling failed. File creation failed.
32100002Encoding failed. Possible causes: 1. Image processing error; 2. Channel coding error.

Example

import image from '@ohos.multimedia.image';
import { metadataBinding } from '@kit.MultimodalAwarenessKit';
import { BusinessError } from '@kit.BasicServicesKit';

let captureImage: image.PixelMap|undefined = undefined;
let metadata: string = "";
let srcImage: image.PixelMap|undefined = undefined;
metadataBinding.encodeImage(srcImage, metadata).then((pixelMap: image.PixelMap) =>{
	captureImage = pixelMap;
}).catch((error:BusinessError)=>{
	console.error("encode image error" + error);
});

decodeImage(image.PixelMap)

function decodeImage(encodedImage: image.PixelMap): Promise<string> Decodes the information carried in the image.

System capability: SystemCapability.MultimodalAwareness.metadataBinding System API: This is a system API.

Parameters

NameTypeMandatoryDescription
encodedImagePixelMapYesImage with metadata encoded.
PromisePromise<string>YesCallback used to return the encoded metadata of the image.

Error codes

For details about the error codes, see Metadata Binding Error Codes and Universal Error Codes.

IDError Message
202Permission check failed. A non-system application uses the system API.
32100001Internal handling failed. File creation failed.
32100003Decoding failed. Possible causes: 1. Image not encoded; 2. Image destroyed.

Example

import image from '@ohos.multimedia.image';
import { metadataBinding } from '@kit.MultimodalAwarenessKit';
import { BusinessError } from '@kit.BasicServicesKit';

let encodeImage: image.PixelMap|undefined = undefined;
let captrueMetadata: string = "";
metadataBinding.decodeImage(encodeImage).then((metadata: string) =>{
	captrueMetadata = metadata;
}).catch((error:BusinessError)=>{
	console.error("decode image error" + error);
}); 

notifyMetadataBindingEvent(string)

notifyMetadataBindingEvent(metadata: string): void; Transfers metadata to the application or service that calls the encoding API. System capability: SystemCapability.MultimodalAwareness.metadataBinding System API: This is a system API.

Parameters

NameTypeMandatoryDescription
metadatastringYesMetadata to be encoded.

Error codes

For details about the error codes, see Metadata Binding Error Codes and Universal Error Codes.

IDError Message
32100001Internal handling failed. File creation failed.

Example

import { metadataBinding } from '@kit.MultimodalAwarenessKit';
import { BusinessError } from '@kit.BasicServicesKit';

let metadata:string = '';
metadataBinding.notifyMetadataBindingEvent(metadata).catch((error: BusinessError)=>{
  console.error("notify metadata error" + error);
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Multimodal Awareness Kit

harmony 鸿蒙Device Status Awareness Error Codes

harmony 鸿蒙Metadata Binding Error Codes

harmony 鸿蒙Motion Awareness Error Codes

harmony 鸿蒙@ohos.multimodalAwareness.deviceStatus (Device Status Awareness)

harmony 鸿蒙@ohos.multimodalAwareness.metadataBinding (Metadata Binding)

harmony 鸿蒙@ohos.multimodalawareness.motion (Motion Awareness)

harmony 鸿蒙@ohos.stationary (Device Status Awareness Framework)

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