1# @ohos.multimodalAwareness.metadataBinding (记忆链接) 2<!--Kit: Multimodal Awareness Kit--> 3<!--Subsystem: Msdp--> 4<!--Owner: @codexu62--> 5<!--Designer: @yuxiaoyang--> 6<!--Tester: @zhaodengqi--> 7<!--Adviser: @hu-zhiqiong--> 8 9本模块提供记忆链接能力调用,用于在图片加入和解析相关信息,完成信息传递。 10 11> **说明:** 12> 13> 本模块首批接口从API version 18开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14> 15> 本模块为系统接口。 16 17 18## 导入模块 19```ts 20import { metadataBinding } from '@kit.MultimodalAwarenessKit'; 21``` 22 23## metadataBinding.encodeImage 24encodeImage(srcImage: image.PixelMap, metadata: string): Promise<image.PixelMap> 25 26在图片中加入信息。 27 28**系统能力**:SystemCapability.MultimodalAwareness.metadataBinding 29 30**系统API**:此接口为系统接口 31 32**参数**: 33 34| 参数名 | 类型 | 必填 | 说明 | 35| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 36| srcImage | PixelMap | 是 | 原始图片。 | 37| metadata | string | 是 | 嵌入的信息。| 38 39**返回值:** 40 41 | 类型 | 说明 | 42 | ---------------------------- | ---------- | 43 | Promise<image.PixelMap> | Promise对象。返回嵌入信息的图片。 | 44 45**错误码**: 46 47以下错误码的详细介绍请参见[记忆链接错误码](errorcode-metadataBinding.md)和[通用错误码](../errorcode-universal.md)。 48 49| 错误码ID | 错误信息 | 50| -------- | ------------------------------------------------------------ | 51| 202 | Permission check failed. A non-system application uses the system API. | 52| 32100001 | Internal handling failed. File creation failed. | 53| 32100002 | Encode process fail. Possible causes: 1. Image processing error; 2. Channel coding error. | 54 55**示例**: 56 57```ts 58import image from '@ohos.multimedia.image'; 59import { metadataBinding } from '@kit.MultimodalAwarenessKit'; 60import { BusinessError } from '@kit.BasicServicesKit'; 61 62let captureImage: image.PixelMap | undefined = undefined; 63let metadata: string = ""; 64let srcImage: image.PixelMap | undefined = undefined; 65metadataBinding.encodeImage(srcImage, metadata).then((pixelMap: image.PixelMap) =>{ 66 captureImage = pixelMap; 67}).catch((error:BusinessError)=>{ 68 console.error("encode image error" + error); 69}); 70``` 71 72## metadataBinding.decodeImage 73function decodeImage(encodedImage: image.PixelMap): Promise<string> 74 75解析图片中携带的信息。 76 77**系统能力**:SystemCapability.MultimodalAwareness.metadataBinding 78 79**系统API**:此接口为系统接口 80 81**参数**: 82 83| 参数名 | 类型 | 必填 | 说明 | 84| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 85| encodedImage | PixelMap | 是 | 带有信息的图片。 | 86 87**返回值:** 88 89 | 类型 | 说明 | 90 | ---------------------------- | ---------- | 91 | Promise<string> | Promise对象。返回从图片解析出的信息。 | 92 93**错误码**: 94 95以下错误码的详细介绍请参见[记忆链接错误码](errorcode-metadataBinding.md)和[通用错误码](../errorcode-universal.md)。 96 97| 错误码ID | 错误信息 | 98| -------- | ------------------------------------------------------------ | 99| 202 | Permission check failed. A non-system application uses the system API. | 100| 32100001 | Internal handling failed. File read failed. | 101| 32100003 | Decode process fail. Possible causes: 1. Image is not an encoded Image; 2. Image destroyed, decoding failed. | 102 103**示例:** 104```ts 105import image from '@ohos.multimedia.image'; 106import { metadataBinding } from '@kit.MultimodalAwarenessKit'; 107import { BusinessError } from '@kit.BasicServicesKit'; 108 109let encodeImage: image.PixelMap | undefined = undefined; 110let captureMetadata: string = ""; 111metadataBinding.decodeImage(encodeImage).then((metadata: string) =>{ 112 captureMetadata = metadata; 113}).catch((error:BusinessError)=>{ 114 console.error("decode image error" + error); 115}); 116``` 117 118## metadataBinding.notifyMetadataBindingEvent 119notifyMetadataBindingEvent(metadata: string): void 120 121推送待嵌入的信息给调用编码接口的应用或服务。 122 123**系统能力**:SystemCapability.MultimodalAwareness.metadataBinding 124 125**系统API**:此接口为系统接口 126 127**参数**: 128 129| 参数名 | 类型 | 必填 | 说明 | 130| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 131| metadata | string | 是 | 要嵌入图片中的信息。 | 132 133**错误码**: 134 135以下错误码的详细介绍请参见[记忆链接错误码](errorcode-metadataBinding.md)和[通用错误码](../errorcode-universal.md)。 136 137| 错误码ID | 错误信息 | 138| -------- | ------------------------------------------------------------ | 139| 202 | Permission check failed. A non-system application uses the system API. | 140| 32100001 | Internal handling failed. Obtain metadata failed. | 141 142**示例**: 143 144```ts 145import { metadataBinding } from '@kit.MultimodalAwarenessKit'; 146import { BusinessError } from '@kit.BasicServicesKit'; 147 148let metadata:string = ''; 149metadataBinding.notifyMetadataBindingEvent(metadata).catch((error: BusinessError)=>{ 150 console.error("notify metadata error" + error); 151}); 152```