diff --git a/zh-cn/application-dev/reference/apis/js-apis-image.md b/zh-cn/application-dev/reference/apis/js-apis-image.md index af4e587c014066f6da0f3ff356c04d2c1eb2290f..37385a4c6fba5dc3b840e82a4de9ab2a36bfc62a 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-image.md +++ b/zh-cn/application-dev/reference/apis/js-apis-image.md @@ -2,12 +2,10 @@ > **说明:** > 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -> -> API Version 9当前为Canary版本,仅供试用,不保证接口可稳定调用。 ## 导入模块 -``` +```js import image from '@ohos.multimedia.image'; ``` @@ -22,8 +20,8 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\ { - }) +const color = new ArrayBuffer(96); +let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } +image.createPixelMap(color, opts) + .then((pixelmap) => { + }) ``` ## image.createPixelMap8+ @@ -51,15 +51,17 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: As | 名称 | 类型 | 必填 | 说明 | | -------- | ------------------------------------------------ | ---- | -------------------------- | -| colors | ArrayBuffer | 是 | 颜色数组。 | -| options | [InitializetionOptions](#initializationoptions8) | 是 | 属性。 | +| colors | ArrayBuffer | 是 | BGRA_8888格式的颜色数组。 | +| options | [InitializationOptions](#initializationoptions8) | 是 | 属性。 | | callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是 | 通过回调返回PixelMap对象。 | **示例:** ```js -image.createPixelMap(Color, opts, (pixelmap) => { - }) +const color = new ArrayBuffer(96); +let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } +image.createPixelMap(color, opts, (pixelmap) => { + }) ``` ## PixelMap7+ @@ -68,9 +70,11 @@ image.createPixelMap(Color, opts, (pixelmap) => { ### 属性 -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ----------------------- | ------- | ---- | ---- | ------------------------------------------------------------ | -| isEditable7+ | boolean | 是 | 否 | 设定是否图像像素可被编辑。
**系统能力:** SystemCapability.Multimedia.Image | +**系统能力:** SystemCapability.Multimedia.Image + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ----------------------- | ------- | ---- | ---- | -------------------------- | +| isEditable7+ | boolean | 是 | 否 | 设定是否图像像素可被编辑。 | ### readPixelsToBuffer7+ @@ -95,11 +99,11 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\ **示例:** ```js -pixelmap.readPixelsToBuffer(readBuffer).then(() => { - //符合条件则进入 - }).catch(error => { - //不符合条件则进入 - }) +pixelmap.readPixelsToBuffer(ReadBuffer).then(() => { + console.log('readPixelsToBuffer succeeded.'); //符合条件则进入 +}).catch(error => { + console.log('readPixelsToBuffer failed.'); //不符合条件则进入 +}) ``` ### readPixelsToBuffer7+ @@ -120,8 +124,13 @@ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\): void **示例:** ```js -pixelmap.readPixelsToBuffer(readBuffer, () => { - }) +pixelmap.readPixelsToBuffer(ReadBuffer, (err, res) => { + if(err) { + console.log('readPixelsToBuffer failed.'); //不符合条件则进入 + } else { + console.log('readPixelsToBuffer succeeded.'); //符合条件则进入 + } +}) ``` ### readPixels7+ @@ -147,11 +156,11 @@ readPixels(area: PositionArea): Promise\ **示例:** ```js -pixelmap.readPixels(area).then((data) => { - //符合条件则进入 - }).catch(error => { - //不符合条件则进入 - }) +pixelmap.readPixels(Area).then((data) => { + console.log('readPixels succeeded.'); //符合条件则进入 +}).catch(error => { + console.log('readPixels failed.'); //不符合条件则进入 +}) ``` ### readPixels7+ @@ -174,19 +183,17 @@ readPixels(area: PositionArea, callback: AsyncCallback\): void ```js let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } image.createPixelMap(color, opts, (err, pixelmap) => { - if(pixelmap == undefined){ - console.info('createPixelMap failed'); - expect(false).assertTrue(); - done(); - }else{ - const area = { pixels: new ArrayBuffer(8), - offset: 0, - stride: 8, - region: { size: { height: 1, width: 2 }, x: 0, y: 0 }} - pixelmap.readPixels(area, () => { - console.info('readPixels success'); - }) - } + if(pixelmap == undefined){ + console.info('createPixelMap failed.'); + } else { + const area = { pixels: new ArrayBuffer(8), + offset: 0, + stride: 8, + region: { size: { height: 1, width: 2 }, x: 0, y: 0 }}; + pixelmap.readPixels(area, () => { + console.info('readPixels success'); + }) + } }) ``` @@ -218,16 +225,14 @@ let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } image.createPixelMap(color, opts) .then( pixelmap => { if (pixelmap == undefined) { - console.info('createPixelMap failed'); - expect(false).assertTrue() - done(); + console.info('createPixelMap failed.'); } const area = { pixels: new ArrayBuffer(8), offset: 0, stride: 8, region: { size: { height: 1, width: 2 }, x: 0, y: 0 } } - var bufferArr = new Uint8Array(area.pixels); + let bufferArr = new Uint8Array(area.pixels); for (var i = 0; i < bufferArr.length; i++) { bufferArr[i] = i + 1; } @@ -240,11 +245,8 @@ image.createPixelMap(color, opts) region: { size: { height: 1, width: 2 }, x: 0, y: 0 } } }) - }) - .catch(error => { + }).catch(error => { console.log('error: ' + error); - expect().assertFail(); - done(); }) ``` @@ -261,19 +263,23 @@ writePixels(area: PositionArea, callback: AsyncCallback\): void | 参数名 | 类型 | 必填 | 说明 | | --------- | ------------------------------ | ---- | ------------------------------ | | area | [PositionArea](#positionarea7) | 是 | 区域,根据区域写入。 | -| callback: | AsyncCallback\ | 是 | 获取回调,失败时返回错误信息。 | +| callback: | AsyncCallback\ | 是 | 获取回调,失败时error会返回错误信息。 | **示例:** ```js -pixelmap.writePixels(area, () => { - const readArea = { - pixels: new ArrayBuffer(20), - offset: 0, - stride: 8, - region: { size: { height: 1, width: 2 }, x: 0, y: 0 }, - } - }) +pixelmap.writePixels(Area, (error) => { + if (error!=undefined) { + console.info('writePixels failed.'); + } else { + const readArea = { + pixels: new ArrayBuffer(20), + offset: 0, + stride: 8, + region: { size: { height: 1, width: 2 }, x: 0, y: 0 }, + } + } +}) ``` ### writeBufferToPixels7+ @@ -299,11 +305,11 @@ writeBufferToPixels(src: ArrayBuffer): Promise\ **示例:** ```js -pixelMap.writeBufferToPixels(colorBuffer).then(() => { +PixelMap.writeBufferToPixels(color).then(() => { console.log("Succeeded in writing data from a buffer to a PixelMap."); }).catch((err) => { console.error("Failed to write data from a buffer to a PixelMap."); -}); +}) ``` ### writeBufferToPixels7+ @@ -324,12 +330,13 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\): void **示例:** ```js -pixelMap.writeBufferToPixels(colorBuffer, function(err) { +PixelMap.writeBufferToPixels(color, function(err) { if (err) { console.error("Failed to write data from a buffer to a PixelMap."); return; - } - console.log("Succeeded in writing data from a buffer to a PixelMap."); + } else { + console.log("Succeeded in writing data from a buffer to a PixelMap."); + } }); ``` @@ -350,7 +357,7 @@ getImageInfo(): Promise\ **示例:** ```js -pixelMap.getImageInfo().then(function(info) { +PixelMap.getImageInfo().then(function(info) { console.log("Succeeded in obtaining the image pixel map information."); }).catch((err) => { console.error("Failed to obtain the image pixel map information."); @@ -374,7 +381,11 @@ getImageInfo(callback: AsyncCallback\): void **示例:** ```js -pixelmap.getImageInfo((imageInfo) => {}) +pixelmap.getImageInfo((imageInfo) => { + console.log("getImageInfo succeeded."); +}).catch((err) => { + console.error("getImageInfo failed."); +}) ``` ### getBytesNumberPerRow7+ @@ -394,7 +405,9 @@ getBytesNumberPerRow(): number **示例:** ```js -rowCount = pixelmap.getBytesNumberPerRow() +image.createPixelMap(clolr, opts, (err,pixelmap) => { + let rowCount = pixelmap.getBytesNumberPerRow(); +}) ``` ### getPixelBytesNumber7+ @@ -414,7 +427,7 @@ getPixelBytesNumber(): number **示例:** ```js -pixelBytesNumber = pixelmap.getPixelBytesNumber() +let pixelBytesNumber = pixelmap.getPixelBytesNumber(); ``` ### release7+ @@ -434,8 +447,13 @@ release():Promise\ **示例:** ```js - pixelmap.release().then(() => { }) - .catch(error => {}) +image.createPixelMap(color, opts, (pixelmap) => { + pixelmap.release().then(() => { + console.log('release succeeded.'); + }).catch(error => { + console.log('release failed.'); + }) +}) ``` ### release7+ @@ -455,7 +473,13 @@ release(callback: AsyncCallback\): void **示例:** ```js -pixelmap.release(()=>{ }) +image.createPixelMap(color, opts, (pixelmap) => { + pixelmap.release().then(() => { + console.log('release succeeded.'); + }).catch(error => { + console.log('release failed.'); + }) +}) ``` ## image.createImageSource @@ -508,7 +532,7 @@ createImageSource(fd: number): ImageSource **示例:** ```js -const imageSourceApi = image.createImageSource(0) +const imageSourceApi = image.createImageSource(0); ``` ## ImageSource @@ -517,9 +541,11 @@ const imageSourceApi = image.createImageSource(0) ### 属性 +**系统能力:** SystemCapability.Multimedia.Image + | 名称 | 类型 | 可读 | 可写 | 说明 | | ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | -| supportedFormats | Array\ | 是 | 否 | 支持的图片格式,包括:png,jpeg,wbmp,bmp,gif,webp,heif等。
**系统能力:** SystemCapability.Multimedia.Image | +| supportedFormats | Array\ | 是 | 否 | 支持的图片格式,包括:png,jpeg,wbmp,bmp,gif,webp,heif等。 | ### getImageInfo @@ -539,7 +565,13 @@ getImageInfo(index: number, callback: AsyncCallback\): void **示例:** ```js -imageSourceApi.getImageInfo(0,(error, imageInfo) => {}) +imageSourceApi.getImageInfo(0,(error, imageInfo) => { + if(error) { + console.log('getImageInfo failed.'); + } else { + console.log('getImageInfo succeeded.'); + } +}) ``` ### getImageInfo @@ -559,7 +591,11 @@ getImageInfo(callback: AsyncCallback\): void **示例:** ```js -imageSourceApi.getImageInfo(imageInfo => {}) +imageSourceApi.getImageInfo(imageInfo => { + console.log('getImageInfo succeeded.'); +}).catch(error => { + console.log('getImageInfo failed.'); +}) ``` ### getImageInfo @@ -586,8 +622,11 @@ getImageInfo(index?: number): Promise\ ```js imageSourceApi.getImageInfo(0) - .then(imageInfo => {}) - .catch(error => {}) + .then(imageInfo => { + console.log('getImageInfo succeeded.'); + }).catch(error => { + console.log('getImageInfo failed.'); + }) ``` ### getImageProperty7+ @@ -615,8 +654,11 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\ {}) - .catch(error => {}) + .then(data => { + console.log('getImageProperty succeeded.'); + }).catch(error => { + console.log('getImageProperty failed.'); + }) ``` ### getImageProperty7+ @@ -637,7 +679,13 @@ getImageProperty(key:string, callback: AsyncCallback\): void **示例:** ```js -imageSourceApi.getImageProperty("BitsPerSample",(error,data) => {}) +imageSourceApi.getImageProperty("BitsPerSample",(error,data) => { + if(error) { + console.log('getImageProperty failed.'); + } else { + console.log('getImageProperty succeeded.'); + } +}) ``` ### getImageProperty7+ @@ -659,7 +707,13 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa **示例:** ```js -imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => {}) +imageSourceApi.getImageProperty("BitsPerSample",Property,(error,data) => { + if(error) { + console.log('getImageProperty failed.'); + } else { + console.log('getImageProperty succeeded.'); + } +}) ``` ### createPixelMap7+ @@ -685,8 +739,11 @@ createPixelMap(options?: DecodingOptions): Promise\ **示例:** ```js -imageSourceApi.createPixelMap().then(pixelmap => {}) - .catch(error => {}) +imageSourceApi.createPixelMap().then(pixelmap => { + console.log('createPixelMap succeeded.'); +}).catch(error => { + console.log('createPixelMap failed.'); +}) ``` ### createPixelMap7+ @@ -706,7 +763,11 @@ createPixelMap(callback: AsyncCallback\): void **示例:** ```js -imageSourceApi.createPixelMap(pixelmap => {}) +imageSourceApi.createPixelMap(pixelmap => { + console.log('createPixelMap succeeded.'); +}).catch(error => { + console.log('createPixelMap failed.'); +}) ``` ### createPixelMap7+ @@ -727,7 +788,11 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\): vo **示例:** ```js -imageSourceApi.createPixelMap(decodingOptions, pixelmap => {}) +imageSourceApi.createPixelMap(decodingOptions, pixelmap => { + console.log('createPixelMap succeeded.'); +}).catch(error => { + console.log('createPixelMap failed.'); +}) ``` ### release @@ -747,7 +812,11 @@ release(callback: AsyncCallback\): void **示例:** ```js -imageSourceApi.release(() => {}) +imageSourceApi.release(() => { + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ### release @@ -767,7 +836,11 @@ release(): Promise\ **示例:** ```js -imageSourceApi.release().then(()=>{ }).catch(error => {}) +imageSourceApi.release().then(()=>{ + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ## image.createImagePacker @@ -796,9 +869,11 @@ const imagePackerApi = image.createImagePacker(); ### 属性 -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | -| supportedFormats | Array\ | 是 | 否 | 图片打包支持的格式,jpeg。
**系统能力:** SystemCapability.Multimedia.Image | +**系统能力:** SystemCapability.Multimedia.Image + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ---------------- | -------------- | ---- | ---- | -------------------------- | +| supportedFormats | Array\ | 是 | 否 | 图片打包支持的格式,jpeg。 | ### packing @@ -814,13 +889,13 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\ | 是 | 获取图片打包回调,返回打包后数据。 | +| callback | AsyncCallback\ | 是 | 获取图片打包回调,返回打包后数据。 | **示例:** ```js -let packOpts = { format:["image/jpeg"], quality:98 } -imagePackerApi.packing(imageSourceApi, packOpts, data => {}) +let packOpts = { format:"image/jpeg", quality:98 }; +imagePackerApi.packing(ImageSourceApi, packOpts, data => {}) ``` ### packing @@ -848,9 +923,12 @@ packing(source: ImageSource, option: PackingOption): Promise\ ```js let packOpts = { format:["image/jpeg"], quality:98 } -imagePackerApi.packing(imageSourceApi, packOpts) - .then( data => { }) - .catch(error => {}) +imagePackerApi.packing(ImageSourceApi, packOpts) + .then( data => { + console.log('packing succeeded.'); + }).catch(error => { + console.log('packing failed.'); + }) ``` ### packing8+ @@ -873,7 +951,11 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\ {}) +imagePackerApi.packing(PixelMapApi, packOpts, data => { + console.log('packing succeeded.'); +}).catch(error => { + console.log('packing failed.'); +}) ``` ### packing8+ @@ -886,10 +968,10 @@ packing(source: PixelMap, option: PackingOption): Promise\ **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------------------- | ---- | -------------- | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------------------------------- | ---- | ------------------ | | source | [PixelMap](#pixelmap) | 是 | 打包的PixelMap源。 | -| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | +| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | **返回值:** @@ -901,9 +983,12 @@ packing(source: PixelMap, option: PackingOption): Promise\ ```js let packOpts = { format:["image/jpeg"], quality:98 } -imagePackerApi.packing(pixelMapApi, packOpts) - .then( data => { }) - .catch(error => {}) +imagePackerApi.packing(PixelMapApi, packOpts) + .then( data => { + console.log('packing succeeded.'); + }).catch(error => { + console.log('packing failed.'); + }) ``` ### release @@ -923,7 +1008,11 @@ release(callback: AsyncCallback\): void **示例:** ```js -imagePackerApi.release(()=>{}) +imagePackerApi.release(()=>{ + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ### release @@ -943,8 +1032,390 @@ release(): Promise\ **示例:** ```js - imagePackerApi.release().then(()=>{ - }).catch((error)=>{}) +imagePackerApi.release().then(()=>{ + console.log('release succeeded.'); +}).catch((error)=>{ + console.log('release failed.'); +}) +``` + +## image.createImageReceiver9+ + +createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver + +通过宽、高、图片格式、容量创建ImageReceiver实例。 + +**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ---------------------- | +| width | number | 是 | 图像的默认宽度。 | +| height | number | 是 | 图像的默认高度。 | +| format | number | 是 | 图像格式。 | +| capacity | number | 是 | 同时访问的最大图像数。 | + +**返回值:** + +| 类型 | 说明 | +| -------------------------------- | --------------------------------------- | +| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 | + +**示例:** + +```js +var receiver = image.createImageReceiver(8192, 8, 4, 8); +``` + +## ImageReceiver9+ + +图像接收类,用于获取组件surface id,接收最新的图片和读取下一张图片,以及释放ImageReceiver实例。 + +在调用以下方法前需要先创建ImageReceiver实例。 + +### 属性 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageReceiver + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| --------------------- | ---------------------------- | ---- | ---- | ------------------ | +| size9+ | [Size](#size) | 是 | 否 | 图片大小。 | +| capacity9+ | number | 是 | 否 | 同时访问的图像数。 | +| format9+ | [ImageFormat](#imageformat9) | 是 | 否 | 图像格式。 | + +### getReceivingSurfaceId9+ + +getReceivingSurfaceId(callback: AsyncCallback\): void + +用于获取一个surface id供Camera或其他组件使用。使用callback返回结果。 + +**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ---------------------- | ---- | -------------------------- | +| callback | AsyncCallback\ | 是 | 回调函数,返回surface id。 | + +**示例:** + +```js + receiver.getReceivingSurfaceId((err, id) => { + if(err) { + console.log('getReceivingSurfaceId failed.'); + } else { + console.log('getReceivingSurfaceId succeeded.'); + } +}); +``` + +### getReceivingSurfaceId9+ + +getReceivingSurfaceId(): Promise\ + +用于获取一个surface id供Camera或其他组件使用。使用promise返回结果。 + +**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver + +**返回值:** + +| 类型 | 说明 | +| ---------------- | -------------------- | +| Promise\ | 异步返回surface id。 | + +**示例:** + +```js +receiver.getReceivingSurfaceId().then( id => { + console.log('getReceivingSurfaceId succeeded.'); +}).catch(error => { + console.log('getReceivingSurfaceId failed.'); +}) +``` + +### readLatestImage9+ + +readLatestImage(callback: AsyncCallback\): void + +从ImageReceiver读取最新的图片,并使用callback返回结果。 + +**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ------------------------------- | ---- | ------------------------ | +| callback | AsyncCallback<[Image](#image9)> | 是 | 回调函数,返回最新图像。 | + +**示例:** + +```js +receiver.readLatestImage((err, img) => { + if(err) { + console.log('readLatestImage failed.'); + } else { + console.log('readLatestImage succeeded.'); + } +}); +``` + +### readLatestImage9+ + +readLatestImage(): Promise\ + +从ImageReceiver读取最新的图片,并使用promise返回结果。 + +**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver + +**返回值:** + +| 类型 | 说明 | +| ------------------------- | ------------------ | +| Promise<[Image](#image8)> | 异步返回最新图片。 | + +**示例:** + +```js +receiver.readLatestImage().then(img => { + console.log('readLatestImage succeeded.'); +}).catch(error => { + console.log('readLatestImage failed.'); +}) +``` + +### readNextImage9+ + +readNextImage(callback: AsyncCallback\): void + +从ImageReceiver读取下一张图片,并使用callback返回结果。 + +**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ------------------------------- | ---- | -------------------------- | +| callback | AsyncCallback<[Image](#image9)> | 是 | 回调函数,返回下一张图片。 | + +**示例:** + +```js +receiver.readNextImage((err, img) => { + if(err) { + console.log('readNextImage failed.'); + } else { + console.log('readNextImage succeeded.'); + } +}); +``` + +### readNextImage9+ + +readNextImage(): Promise\ + +从ImageReceiver读取下一张图片,并使用promise返回结果。 + +**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver + +**返回值:** + +| 类型 | 说明 | +| ------------------------- | -------------------- | +| Promise<[Image](#image9)> | 异步返回下一张图片。 | + +**示例:** + +```js +receiver.readNextImage().then(img => { + console.log('readNextImage succeeded.'); +}).catch(error => { + console.log('readNextImage failed.'); +}) +``` + +### on('imageArrival')9+ + +on(type: 'imageArrival', callback: AsyncCallback\): void + +接收图片时注册回调。 + +**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------------------------------------ | +| type | string | 是 | 注册事件的类型,固定为'imageArrival',接收图片时触发。 | +| callback | AsyncCallback\ | 是 | 注册的事件回调。 | + +**示例:** + +```js +receiver.on('imageArrival', () => {}) +``` + +### release9+ + +release(callback: AsyncCallback\): void + +释放ImageReceiver实例并使用回调返回结果。 + +**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback\ | 是 | 回调函数,返回操作结果。 | + +**示例:** + +```js +receiver.release(() => {}) +``` + +### release9+ + +release(): Promise\ + +释放ImageReceiver实例并使用promise返回结果。 + +**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver + +**返回值:** + +| 类型 | 说明 | +| -------------- | ------------------ | +| Promise\ | 异步返回操作结果。 | + +**示例:** + +```js +receiver.release().then(() => { + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) +``` + +## Image9+ + +提供基本的图像操作,包括获取图像信息、读写图像数据。调用[readNextImage](#readnextimage9)和[readLatestImage](#readlatestimage9)接口时会返回image。 + +### 属性 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| --------------------- | ------------------ | ---- | ---- | -------------------------------------------------- | +| clipRect9+ | [Region](#region7) | 是 | 是 | 要裁剪的图像区域。 | +| size9+ | [Size](#size) | 是 | 否 | 图像大小。 | +| format9+ | number | 是 | 否 | 图像格式,参考[PixelMapFormat](#pixelmapformat7)。 | + +### getComponent9+ + +getComponent(componentType: ComponentType, callback: AsyncCallback\): void + +根据图像的组件类型从图像中获取组件缓存并使用callback返回结果。 + +**系统能力:** SystemCapability.Multimedia.Image.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ------------- | --------------------------------------- | ---- | -------------------- | +| componentType | [ComponentType](#componenttype9) | 是 | 图像的组件类型。 | +| callback | AsyncCallback<[Component](#component9)> | 是 | 用于返回组件缓冲区。 | + +**示例:** + +```js +img.getComponent(4, (err, component) => { + if(err) { + console.log('getComponent failed.'); + } else { + console.log('getComponent succeeded.'); + } +}) +``` + +### getComponent9+ + +getComponent(componentType: ComponentType): Promise\ + +根据图像的组件类型从图像中获取组件缓存并使用Promise方式返回结果。 + +**系统能力:** SystemCapability.Multimedia.Image.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ------------- | -------------------------------- | ---- | ---------------- | +| componentType | [ComponentType](#componenttype9) | 是 | 图像的组件类型。 | + +**返回值:** + +| 类型 | 说明 | +| --------------------------------- | --------------------------------- | +| Promise<[Component](#component9)> | 用于返回组件缓冲区的promise实例。 | + +**示例:** + +```js +img.getComponent(4).then(component => { }) +``` + +### release9+ + +release(callback: AsyncCallback\): void + +释放当前图像并使用callback返回结果。 + +在接收另一个图像前必须先释放对应资源。 + +**系统能力:** SystemCapability.Multimedia.Image.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | -------------- | +| callback | AsyncCallback\ | 是 | 返回操作结果。 | + +**示例:** + +```js +img.release(() =>{ + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) +``` + +### release9+ + +release(): Promise\ + +释放当前图像并使用Promise方式返回结果。 + +在接收另一个图像前必须先释放对应资源。 + +**系统能力:** SystemCapability.Multimedia.Image.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------- | +| Promise\ | promise返回操作结果。 | + +**示例:** + +```js +img.release().then(() =>{ + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ## PositionArea7+ @@ -957,7 +1428,7 @@ release(): Promise\ | ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ | | pixels | ArrayBuffer | 是 | 否 | 像素。 | | offset | number | 是 | 否 | 偏移量。 | -| stride | number | 是 | 否 | 像素间距,stride >= region.size.width*4。 | +| stride | number | 是 | 否 | 像素间距,stride >= region.size.width*4。 | | region | [Region](#region7) | 是 | 否 | 区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度 | ## ImageInfo @@ -983,7 +1454,7 @@ release(): Promise\ ## PixelMapFormat7+ -枚举,像素格式。 +枚举,图片像素格式。 **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image @@ -995,7 +1466,7 @@ release(): Promise\ ## AlphaType9+ -枚举,透明度。 +枚举,图像的透明度类型。 **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image @@ -1008,7 +1479,7 @@ release(): Promise\ ## ScaleMode9+ -枚举,缩略值。 +枚举,图像的缩放模式。 **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image @@ -1019,19 +1490,21 @@ release(): Promise\ ## InitializationOptions8+ +PixelMap的初始化选项。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ----------- | ---------------------------------- | ---- | ---- | -------------- | -| alphaType9+ | [AlphaType](#alphatype9) | 是 | 是 | 透明度。 | -| editable | boolean | 是 | 是 | 是否可编辑。 | -| pixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 像素格式。 | -| scaleMode9+ | [ScaleMode](#scalemode9) | 是 | 是 | 缩略值。 | -| size | [Size](#size) | 是 | 是 | 创建图片大小。 | +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ---------------------- | ---------------------------------- | ---- | ---- | -------------- | +| alphaType9+ | [AlphaType](#alphatype9) | 是 | 是 | 透明度。 | +| editable | boolean | 是 | 是 | 是否可编辑。 | +| pixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 像素格式。 | +| scaleMode9+ | [ScaleMode](#scalemode9) | 是 | 是 | 缩略值。 | +| size | [Size](#size) | 是 | 是 | 创建图片大小。 | ## DecodingOptions7+ -解码设置选项。 +图像解码设置选项。 **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image @@ -1043,7 +1516,7 @@ release(): Promise\ | desiredSize | [Size](#size) | 是 | 是 | 期望输出大小。 | | desiredRegion | [Region](#region7) | 是 | 是 | 解码区域。 | | desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 解码的像素格式。 | -| index | numer | 是 | 是 | 解码图片序号 | +| index | number | 是 | 是 | 解码图片序号 | ## Region7+ @@ -1066,7 +1539,7 @@ release(): Promise\ | 名称 | 类型 | 可读 | 可写 | 说明 | | ------- | ------ | ---- | ---- | -------------- | | format | string | 是 | 是 | 目标格式。 | -| quality | number | 是 | 是 | 目标图片质量。 | +| quality | number | 是 | 是 | JPEG编码中设定输出图片质量的参数,取值范围为1-100。 | ## GetImagePropertyOptions7+ @@ -1096,3 +1569,40 @@ release(): Promise\ | GPS_LATITUDE_REF | "GPSLatitudeRef" | 纬度引用,例如N或S。 | | GPS_LONGITUDE_REF | "GPSLongitudeRef" | 经度引用,例如W或E。 | +## ImageFormat9+ + +枚举,图片格式。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core + +| 名称 | 默认值 | 描述 | +| ------------ | ------ | -------------------- | +| YCBCR_422_SP | 1000 | YCBCR422半平面格式。 | +| JPEG | 2000 | JPEG编码格式。 | + +## ComponentType9+ + +枚举,图像的组件类型。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageReceiver + +| 名称 | 默认值 | 描述 | +| ----- | ------ | ----------- | +| YUV_Y | 1 | 亮度信息。 | +| YUV_U | 2 | 色度信息。 | +| YUV_V | 3 | 色度信息。 | +| JPEG | 4 | Jpeg 类型。 | + +## Component9+ + +描述图像颜色分量。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ------------- | -------------------------------- | ---- | ---- | ------------ | +| componentType | [ComponentType](#componenttype9) | 是 | 否 | 组件类型。 | +| rowStride | number | 是 | 否 | 行距。 | +| pixelStride | number | 是 | 否 | 像素间距。 | +| byteBuffer | ArrayBuffer | 是 | 否 | 组件缓冲区。 | +