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 42e133251a58664a1a1984c40e9dd402ffa3e734..10f95e30a2a4f038b27b131e6b98cd36bf7b5fc9 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-image.md +++ b/zh-cn/application-dev/reference/apis/js-apis-image.md @@ -20,7 +20,7 @@ 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+ @@ -49,15 +51,17 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: As | 名称 | 类型 | 必填 | 说明 | | -------- | ------------------------------------------------ | ---- | -------------------------- | -| colors | ArrayBuffer | 是 | 颜色数组。 | +| 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+ @@ -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,9 +225,7 @@ 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, @@ -243,8 +248,6 @@ image.createPixelMap(color, opts) }) .catch(error => { console.log('error: ' + error); - expect().assertFail(); - done(); }) ``` @@ -266,14 +269,14 @@ writePixels(area: PositionArea, callback: AsyncCallback\): void **示例:** ```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, () => { + const readArea = { + pixels: new ArrayBuffer(20), + offset: 0, + stride: 8, + region: { size: { height: 1, width: 2 }, x: 0, y: 0 }, + } +}) ``` ### writeBufferToPixels7+ @@ -299,11 +302,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 +327,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 +354,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 +378,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 +402,9 @@ getBytesNumberPerRow(): number **示例:** ```js -rowCount = pixelmap.getBytesNumberPerRow() +image.createPixelMap(clolr, opts, (err,pixelmap) => { + let rowCount = pixelmap.getBytesNumberPerRow(); +}) ``` ### getPixelBytesNumber7+ @@ -414,7 +424,7 @@ getPixelBytesNumber(): number **示例:** ```js -pixelBytesNumber = pixelmap.getPixelBytesNumber() +let pixelBytesNumber = pixelmap.getPixelBytesNumber(); ``` ### release7+ @@ -434,8 +444,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 +470,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 +529,7 @@ createImageSource(fd: number): ImageSource **示例:** ```js -const imageSourceApi = image.createImageSource(0) +const imageSourceApi = image.createImageSource(0); ``` ## ImageSource @@ -541,7 +562,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 @@ -561,7 +588,11 @@ getImageInfo(callback: AsyncCallback\): void **示例:** ```js -imageSourceApi.getImageInfo(imageInfo => {}) +imageSourceApi.getImageInfo(imageInfo => { + console.log('getImageInfo succeeded.'); +}).catch(error => { + console.log('getImageInfo failed.'); +}) ``` ### getImageInfo @@ -588,8 +619,12 @@ 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+ @@ -617,8 +652,12 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\ {}) - .catch(error => {}) + .then(data => { + console.log('getImageProperty succeeded.'); + }) + .catch(error => { + console.log('getImageProperty failed.'); + }) ``` ### getImageProperty7+ @@ -639,7 +678,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+ @@ -661,7 +706,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+ @@ -687,8 +738,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+ @@ -708,7 +762,11 @@ createPixelMap(callback: AsyncCallback\): void **示例:** ```js -imageSourceApi.createPixelMap(pixelmap => {}) +imageSourceApi.createPixelMap(pixelmap => { + console.log('createPixelMap succeeded.'); +}).catch(error => { + console.log('createPixelMap failed.'); +}) ``` ### createPixelMap7+ @@ -729,7 +787,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 @@ -749,7 +811,11 @@ release(callback: AsyncCallback\): void **示例:** ```js -imageSourceApi.release(() => {}) +imageSourceApi.release(() => { + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ### release @@ -769,7 +835,11 @@ release(): Promise\ **示例:** ```js -imageSourceApi.release().then(()=>{ }).catch(error => {}) +imageSourceApi.release().then(()=>{ + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ## image.createImagePacker @@ -823,8 +893,8 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\ {}) +let packOpts = { format:["image/jpeg"], quality:98 }; +imagePackerApi.packing(ImageSourceApi, packOpts, data => {}) ``` ### packing @@ -852,9 +922,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+ @@ -877,7 +950,11 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\ {}) +imagePackerApi.packing(PixelMapApi, packOpts, data => { + console.log('packing succeeded.'); +}).catch(error => { + console.log('packing failed.'); +}) ``` ### packing8+ @@ -905,9 +982,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 @@ -927,7 +1007,11 @@ release(callback: AsyncCallback\): void **示例:** ```js -imagePackerApi.release(()=>{}) +imagePackerApi.release(()=>{ + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ### release @@ -947,8 +1031,11 @@ release(): Promise\ **示例:** ```js - imagePackerApi.release().then(()=>{ - }).catch((error)=>{}) +imagePackerApi.release().then(()=>{ + console.log('release succeeded.'); +}).catch((error)=>{ + console.log('release failed.'); +}) ``` ## image.createImageReceiver9+ @@ -977,7 +1064,7 @@ createImageReceiver(width: number, height: number, format: number, capacity: num **示例:** ```js -var receiver = image.createImageReceiver(8192, 8, 4, 8) +var receiver = image.createImageReceiver(8192, 8, 4, 8); ``` ## ImageReceiver9+ @@ -1013,7 +1100,13 @@ getReceivingSurfaceId(callback: AsyncCallback\): void **示例:** ```js - receiver.getReceivingSurfaceId((err, id) => {}); + receiver.getReceivingSurfaceId((err, id) => { + if(err) { + console.log('getReceivingSurfaceId failed.'); + } else { + console.log('getReceivingSurfaceId succeeded.'); + } +}); ``` ### getReceivingSurfaceId9+ @@ -1034,8 +1127,10 @@ getReceivingSurfaceId(): Promise\ ```js receiver.getReceivingSurfaceId().then( id => { - }).catch(error => { - }) + console.log('getReceivingSurfaceId succeeded.'); +}).catch(error => { + console.log('getReceivingSurfaceId failed.'); +}) ``` ### readLatestImage9+ @@ -1055,7 +1150,13 @@ readLatestImage(callback: AsyncCallback\): void **示例:** ```js - receiver.readLatestImage((err, img) => { }); +receiver.readLatestImage((err, img) => { + if(err) { + console.log('readLatestImage failed.'); + } else { + console.log('readLatestImage succeeded.'); + } +}); ``` ### readLatestImage9+ @@ -1075,8 +1176,11 @@ readLatestImage(): Promise\ **示例:** ```js -receiver.readLatestImage().then(img => {}) - .catch(error => {}) +receiver.readLatestImage().then(img => { + console.log('readLatestImage succeeded.'); +}).catch(error => { + console.log('readLatestImage failed.'); +}) ``` ### readNextImage9+ @@ -1096,7 +1200,13 @@ readNextImage(callback: AsyncCallback\): void **示例:** ```js -receiver.readNextImage((err, img) => {}); +receiver.readNextImage((err, img) => { + if(err) { + console.log('readNextImage failed.'); + } else { + console.log('readNextImage succeeded.'); + } +}); ``` ### readNextImage9+ @@ -1116,9 +1226,11 @@ readNextImage(): Promise\ **示例:** ```js - receiver.readNextImage().then(img => { - }).catch(error => { - }) +receiver.readNextImage().then(img => { + console.log('readNextImage succeeded.'); +}).catch(error => { + console.log('readNextImage failed.'); +}) ``` ### on('imageArrival')9+ @@ -1139,7 +1251,7 @@ on(type: 'imageArrival', callback: AsyncCallback\): void **示例:** ```js - receiver.on('imageArrival', () => {}) +receiver.on('imageArrival', () => {}) ``` ### release9+ @@ -1159,7 +1271,7 @@ release(callback: AsyncCallback\): void **示例:** ```js - receiver.release(() => {}) +receiver.release(() => {}) ``` ### release9+ @@ -1179,8 +1291,11 @@ release(): Promise\ **示例:** ```js - receiver.release().then(() => {}) - .catch(error => {}) +receiver.release().then(() => { + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ## Image9+ @@ -1215,7 +1330,13 @@ getComponent(componentType: ComponentType, callback: AsyncCallback\): **示例:** ```js - img.getComponent(4, (err, component) => {}) +img.getComponent(4, (err, component) => { + if(err) { + console.log('getComponent failed.'); + } else { + console.log('getComponent succeeded.'); + } +}) ``` ### getComponent9+ @@ -1263,7 +1384,11 @@ release(callback: AsyncCallback\): void **示例:** ```js -img.release(() =>{ }) +img.release(() =>{ + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ### release9+ @@ -1286,8 +1411,10 @@ release(): Promise\ ```js img.release().then(() =>{ - }).catch(error => { - }) + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ## PositionArea7+