1# @ohos.multimodalAwareness.metadataBinding (Metadata Binding) 2 3The **metadataBinding** module provides the capability of adding metadata to images and parsing the metadata to complete information transfer. 4 5> **NOTE** 6> 7> 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. 8> 9> The APIs provided by this module are system APIs. 10 11 12## Modules to Import 13```ts 14import { metadataBinding } from '@ohos.multimodalAwareness'; 15``` 16 17## encodeImage(image.PixelMap, string) 18encodeImage(srcImage: image.PixelMap, metadata: string): Promise<image.PixelMap>; 19Encodes metadata into an image. 20**System capability**: SystemCapability.MultimodalAwarness.metadataBinding 21**System API**: This is a system API. 22 23**Parameters** 24 25| Name | Type | Mandatory| Description | 26| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 27| srcImage | PixelMap | Yes | Source image.| 28| metadata | string | Yes | Metadata to encoded.| 29| Promise | Promise<image.PixelMap> | Yes | Callback used to return the image with encoded metadata.| 30 31**Error codes** 32 33For details about the error codes, see [Metadata Binding Error Codes](errorcode-metadataBinding.md) and [Universal Error Codes](../errorcode-universal.md). 34 35| ID| Error Message | 36| -------- | ------------------------------------------------------------ | 37| 202 | Permission check failed. A non-system application uses the system API.| 38|32100001 | Internal handling failed. File creation failed.| 39|32100002 | Encode process fail.| 40 41**Example** 42 43```ts 44import image from '@ohos.multimedia.image'; 45import { metadataBinding } from '@ohos.multimodalAwareness'; 46import { BusinessError } from '@kit.BasicServicesKit'; 47 48let captureImage: image.PixelMap | undefined = undefined; 49let metadata: string = ""; 50let srcImage: image.PixelMap | undefined = undefined; 51metadataBinding.encodeImage(srcImage, metadata).then((pixelMap: image.PixelMap) =>{ 52 captureImage = pixelMap; 53}).catch((error:BusinessError)=>{ 54 console.error("encode image error" + error); 55}); 56``` 57 58## decodeImage(image.PixelMap) 59function decodeImage(encodedImage: image.PixelMap): Promise\<string\> 60Decodes the information carried in the image. 61 62**System capability**: SystemCapability.MultimodalAwarness.metadataBinding 63**System API**: This is a system API. 64 65**Parameters** 66 67| Name | Type | Mandatory| Description | 68| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 69| encodedImage | PixelMap | Yes | Image with metadata encoded.| 70|Promise|Promise\<string\>|Yes|Callback used to return the encoded metadata of the image.| 71 72**Error codes** 73 74For details about the error codes, see [Metadata Binding Error Codes](errorcode-metadataBinding.md) and [Universal Error Codes](../errorcode-universal.md). 75 76| ID| Error Message | 77| -------- | ------------------------------------------------------------ | 78| 202 | Permission check failed. A non-system application uses the system API.| 79|32100001 | Internal handling failed. File read failed.| 80|32100003 | Decode process fail.| 81 82**Example** 83```ts 84import image from '@ohos.multimedia.image'; 85import { metadataBinding } from '@ohos.multimodalAwareness'; 86import { BusinessError } from '@kit.BasicServicesKit'; 87 88let encodeImage: image.PixelMap | undefined = undefined; 89let captrueMetadata: string = ""; 90metadataBinding.decodeImage(encodeImage).then((metadata: string) =>{ 91 captrueMetadata = metadata; 92}).catch((error:BusinessError)=>{ 93 console.error("decode image error" + error); 94}); 95``` 96 97## notifyMetadataBindingEvent(string) 98notifyMetadataBindingEvent(metadata: string): void; 99Transfers metadata to the application or service that calls the encoding API. 100**System capability**: SystemCapability.MultimodalAwarness.metadataBinding 101**System API**: This is a system API. 102 103**Parameters** 104 105| Name | Type | Mandatory| Description | 106| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 107| metadata | string | Yes | Metadata to be encoded.| 108 109**Error codes** 110 111For details about the error codes, see [Metadata Binding Error Codes](errorcode-metadataBinding.md) and [Universal Error Codes](../errorcode-universal.md). 112 113| ID| Error Message | 114| -------- | ------------------------------------------------------------ | 115|32100001|Internal handling failed. Obtain metadata failed.| 116 117**Example** 118 119```ts 120import { metadataBinding } from '@ohos.multimodalAwareness'; 121import { BusinessError } from '@kit.BasicServicesKit'; 122 123let metadata:string = ''; 124metadataBinding.notifyMetadataBindingEvent(metadata).catch((error: BusinessError)=>{ 125 console.error("notify metadata error" + error); 126}); 127``` 128