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 863db6376bb4209ff09da5c8744a55564ad0c450..eb4de48fcecb6229486e733b102f2da2960aba7e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-image.md +++ b/zh-cn/application-dev/reference/apis/js-apis-image.md @@ -7,7 +7,7 @@ ## 导入模块 -```js +```ts import image from '@ohos.multimedia.image'; ``` @@ -35,7 +35,7 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\ { +image.createPixelMap(color, opts, (error : BusinessError, pixelmap : image.PixelMap) => { if(error) { console.log('Failed to create pixelmap.'); } else { @@ -112,7 +112,7 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' const readBuffer : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 pixelmap.readPixelsToBuffer(readBuffer).then(() => { @@ -139,9 +139,10 @@ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\): void **示例:** -```js +```ts +import {BusinessError} from '@ohos.base' const readBuffer : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 -pixelmap.readPixelsToBuffer(readBuffer, (err, res) => { +pixelmap.readPixelsToBuffer(readBuffer, (err : BusinessError, res : Object) => { if(err) { console.log('Failed to read image pixel data.'); //不符合条件则进入 } else { @@ -172,7 +173,7 @@ readPixels(area: PositionArea): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' const area : image.PositionArea = { pixels: new ArrayBuffer(8), @@ -204,11 +205,12 @@ readPixels(area: PositionArea, callback: AsyncCallback\): void **示例:** -```js +```ts +import {BusinessError} from '@ohos.base' const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 let bufferArr : Uint8Array = new Uint8Array(color); let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } -image.createPixelMap(color, opts, (err, pixelmap : image.PixelMap) => { +image.createPixelMap(color, opts, (err : BusinessError, pixelmap : image.PixelMap) => { if(pixelmap == undefined){ console.info('createPixelMap failed.'); } else { @@ -245,7 +247,7 @@ writePixels(area: PositionArea): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 let bufferArr : Uint8Array = new Uint8Array(color); @@ -261,7 +263,7 @@ image.createPixelMap(color, opts) region: { size: { height: 1, width: 2 }, x: 0, y: 0 } } let bufferArr : Uint8Array = new Uint8Array(area.pixels); - for (var i = 0; i < bufferArr.length; i++) { + for (let i = 0; i < bufferArr.length; i++) { bufferArr[i] = i + 1; } @@ -290,17 +292,18 @@ writePixels(area: PositionArea, callback: AsyncCallback\): void **示例:** -```js +```ts +import {BusinessError} from '@ohos.base' const area : image.PositionArea = { pixels: new ArrayBuffer(8), offset: 0, stride: 8, region: { size: { height: 1, width: 2 }, x: 0, y: 0 } } let bufferArr : Uint8Array = new Uint8Array(area.pixels); -for (var i = 0; i < bufferArr.length; i++) { +for (let i = 0; i < bufferArr.length; i++) { bufferArr[i] = i + 1; } -pixelmap.writePixels(area, (error) => { +pixelmap.writePixels(area, (error : BusinessError) => { if (error != undefined) { console.info('Failed to write pixelmap into the specified area.'); } else { @@ -331,11 +334,11 @@ writeBufferToPixels(src: ArrayBuffer): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 let bufferArr : Uint8Array = new Uint8Array(color); -for (var i = 0; i < bufferArr.length; i++) { +for (let i = 0; i < bufferArr.length; i++) { bufferArr[i] = i + 1; } pixelmap.writeBufferToPixels(color).then(() => { @@ -362,13 +365,14 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\): void **示例:** -```js +```ts +import {BusinessError} from '@ohos.base' const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 let bufferArr : Uint8Array = new Uint8Array(color); -for (var i = 0; i < bufferArr.length; i++) { +for (let i = 0; i < bufferArr.length; i++) { bufferArr[i] = i + 1; } -pixelmap.writeBufferToPixels(color, function(err) { +pixelmap.writeBufferToPixels(color, (err : BusinessError) => { if (err) { console.error("Failed to write data from a buffer to a PixelMap."); return; @@ -394,7 +398,7 @@ getImageInfo(): Promise\ **示例:** -```js +```ts const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 let opts : image.InitializationOptions = { editable: true, pixelFormat: 2, size: { height: 6, width: 8 } } image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => { @@ -428,14 +432,15 @@ getImageInfo(callback: AsyncCallback\): void **示例:** -```js +```ts +import {BusinessError} from '@ohos.base' const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } -image.createPixelMap(color, opts, (err, pixelmap : image.PixelMap) => { +image.createPixelMap(color, opts, (err : BusinessError, pixelmap : image.PixelMap) => { if (pixelmap == undefined) { console.error("Failed to obtain the image pixel map information."); } - pixelmap.getImageInfo((err, imageInfo : image.ImageInfo) => { + pixelmap.getImageInfo((err : BusinessError, imageInfo : image.ImageInfo) => { if (imageInfo == undefined) { console.error("Failed to obtain the image pixel map information."); } @@ -462,11 +467,12 @@ getBytesNumberPerRow(): number **示例:** -```js +```ts +import {BusinessError} from '@ohos.base' const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 let bufferArr : Uint8Array = new Uint8Array(color); let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } -image.createPixelMap(color, opts, (err,pixelmap : image.PixelMap) => { +image.createPixelMap(color, opts, (err : BusinessError, pixelmap : image.PixelMap) => { let rowCount : number = pixelmap.getBytesNumberPerRow(); }) ``` @@ -487,7 +493,7 @@ getPixelBytesNumber(): number **示例:** -```js +```ts let pixelBytesNumber : number = pixelmap.getPixelBytesNumber(); ``` @@ -507,7 +513,7 @@ getDensity():number **示例:** -```js +```ts let getDensity : number = pixelmap.getDensity(); ``` @@ -528,9 +534,10 @@ opacity(rate: number, callback: AsyncCallback\): void **示例:** -```js -var rate = 0.5; -pixelmap.opacity(rate, (err) => { +```ts +import {BusinessError} from '@ohos.base' +let rate = 0.5; +pixelmap.opacity(rate, (err : BusinessError) => { if (err) { console.error("Failed to set opacity."); return; @@ -562,7 +569,7 @@ opacity(rate: number): Promise\ **示例:** -```js +```ts async function Demo() { await pixelmap.opacity(0.5); } @@ -584,7 +591,7 @@ createAlphaPixelmap(): Promise\ **示例:** -```js +```ts async function Demo() { await pixelmap.createAlphaPixelmap(); } @@ -606,8 +613,9 @@ createAlphaPixelmap(callback: AsyncCallback\): void **示例:** -```js -pixelmap.createAlphaPixelmap((err, alphaPixelMap : image.PixelMap) => { +```ts +import {BusinessError} from '@ohos.base' +pixelmap.createAlphaPixelmap((err : BusinessError, alphaPixelMap : image.PixelMap) => { if (alphaPixelMap == undefined) { console.info('Failed to obtain new pixel map.'); } else { @@ -634,7 +642,7 @@ scale(x: number, y: number, callback: AsyncCallback\): void **示例:** -```js +```ts async function Demo() { await pixelmap.scale(2.0, 1.0); } @@ -663,7 +671,7 @@ scale(x: number, y: number): Promise\ **示例:** -```js +```ts async function Demo() { await pixelmap.scale(2.0, 1.0); } @@ -687,7 +695,7 @@ translate(x: number, y: number, callback: AsyncCallback\): void **示例:** -```js +```ts async function Demo() { await pixelmap.translate(3.0, 1.0); } @@ -716,7 +724,7 @@ translate(x: number, y: number): Promise\ **示例:** -```js +```ts async function Demo() { await pixelmap.translate(3.0, 1.0); } @@ -739,9 +747,10 @@ rotate(angle: number, callback: AsyncCallback\): void **示例:** -```js -var angle = 90.0; -pixelmap.rotate(angle, (err) => { +```ts +import {BusinessError} from '@ohos.base' +let angle = 90.0; +pixelmap.rotate(angle, (err : BusinessError) => { if (err) { console.error("Failed to set rotation."); return; @@ -773,7 +782,7 @@ rotate(angle: number): Promise\ **示例:** -```js +```ts async function Demo() { await pixelmap.rotate(90.0); } @@ -797,7 +806,7 @@ flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\): vo **示例:** -```js +```ts async function Demo() { await pixelmap.flip(false, true); } @@ -826,7 +835,7 @@ flip(horizontal: boolean, vertical: boolean): Promise\ **示例:** -```js +```ts async function Demo() { await pixelmap.flip(false, true); } @@ -849,7 +858,7 @@ crop(region: Region, callback: AsyncCallback\): void **示例:** -```js +```ts async function Demo() { await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } }); } @@ -877,7 +886,7 @@ crop(region: Region): Promise\ **示例:** -```js +```ts async function Demo() { await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } }); } @@ -909,10 +918,10 @@ getColorSpace(): colorSpaceManager.ColorSpaceManager **示例:** -```js +```ts import colorSpaceManager from '@ohos.graphics.colorSpaceManager'; async function Demo() { - let csm = pixelmap.getColorSpace(); + let csm : Object = pixelmap.getColorSpace(); } ``` @@ -941,11 +950,11 @@ setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void **示例:** -```js +```ts import colorSpaceManager from '@ohos.graphics.colorSpaceManager'; async function Demo() { let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; - var csm = colorSpaceManager.create(colorSpaceName); + let csm : colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); pixelmap.setColorSpace(csm); } ``` @@ -975,19 +984,19 @@ marshalling(sequence: rpc.MessageSequence): void **示例:** -```js +```ts import image from '@ohos.multimedia.image' import rpc from '@ohos.rpc' class MySequence { pixel_map; - constructor(pixelmap) { + constructor(pixelmap : image.PixelMap) { this.pixel_map = pixelmap; } - marshalling(messageSequence) { + marshalling(messageSequence : rpc.MessageSequence) { this.pixel_map.marshalling(messageSequence); return true; } - async unmarshalling(messageSequence) { + async unmarshalling(messageSequence : rpc.MessageSequence) { let pixelParcel : image.PixelMap = await image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}); await pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => { this.pixel_map = pixelMap; @@ -1030,23 +1039,23 @@ unmarshalling(sequence: rpc.MessageSequence): Promise\ | ------- | --------------------------------------------| | 62980115 | If the input parameter invalid | | 62980097 | If the ipc error | -| 62980096 | If the Operation failed | +| 62980096 | If fail to create async work | **示例:** -```js +```ts import image from '@ohos.multimedia.image' import rpc from '@ohos.rpc' class MySequence { pixel_map; - constructor(pixelmap) { + constructor(pixelmap : image.PixelMap) { this.pixel_map = pixelmap; } - marshalling(messageSequence) { + marshalling(messageSequence : rpc.MessageSequence) { this.pixel_map.marshalling(messageSequence); return true; } - async unmarshalling(messageSequence) { + async unmarshalling(messageSequence : rpc.MessageSequence) { let pixelParcel : image.PixelMap = await image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}); await pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => { this.pixel_map = pixelMap; @@ -1078,7 +1087,7 @@ release():Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' pixelmap.release().then(() => { console.log('Succeeded in releasing pixelmap object.'); @@ -1103,7 +1112,7 @@ release(callback: AsyncCallback\): void **示例:** -```js +```ts pixelmap.release(() => { console.log('Succeeded in releasing pixelmap object.'); }) @@ -1131,19 +1140,19 @@ createImageSource(uri: string): ImageSource **示例:** -```js +```ts //Stage模型 const context : Context = getContext(this); -const path : string= context.cacheDir + "/test.jpg"; +const path : string = context.cacheDir + "/test.jpg"; const imageSourceApi : image.ImageSource = image.createImageSource(path); ``` -```js +```ts //FA模型 import featureAbility from '@ohos.ability.featureAbility'; const context : Context = featureAbility.getContext(); -const path : string= context.getCacheDir() + "/test.jpg"; +const path : string = context.getCacheDir() + "/test.jpg"; const imageSourceApi : image.ImageSource = image.createImageSource(path); ``` @@ -1170,8 +1179,8 @@ createImageSource(uri: string, options: SourceOptions): ImageSource **示例:** -```js -var sourceOptions : image.SourceOptions = { sourceDensity: 120 }; +```ts +let sourceOptions : image.SourceOptions = { sourceDensity: 120 }; let imageSource : image.ImageSource = image.createImageSource('test.png', sourceOptions); ``` @@ -1197,7 +1206,7 @@ createImageSource(fd: number): ImageSource **示例:** -```js +```ts const imageSourceApi : image.ImageSource = image.createImageSource(0); ``` @@ -1224,8 +1233,8 @@ createImageSource(fd: number, options: SourceOptions): ImageSource **示例:** -```js -var sourceOptions : image.SourceOptions = { sourceDensity: 120 }; +```ts +let sourceOptions : image.SourceOptions = { sourceDensity: 120 }; const imageSourceApi : image.ImageSource = image.createImageSource(0, sourceOptions); ``` @@ -1245,7 +1254,7 @@ createImageSource(buf: ArrayBuffer): ImageSource **示例:** -```js +```ts const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const imageSourceApi : image.ImageSource = image.createImageSource(buf); ``` @@ -1273,7 +1282,7 @@ createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource **示例:** -```js +```ts const data : ArrayBuffer= new ArrayBuffer(112); const imageSourceApi : image.ImageSource = image.createImageSource(data); ``` @@ -1300,7 +1309,7 @@ CreateIncrementalSource(buf: ArrayBuffer): ImageSource **示例:** -```js +```ts const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const imageSourceIncrementalSApi : image.ImageSource = image.CreateIncrementalSource(buf); ``` @@ -1328,7 +1337,7 @@ CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource **示例:** -```js +```ts const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const imageSourceIncrementalSApi : image.ImageSource = image.CreateIncrementalSource(buf); ``` @@ -1362,8 +1371,9 @@ getImageInfo(index: number, callback: AsyncCallback\): void **示例:** -```js -imageSourceApi.getImageInfo(0,(error, imageInfo : image.ImageInfo) => { +```ts +import {BusinessError} from '@ohos.base' +imageSourceApi.getImageInfo(0,(error : BusinessError, imageInfo : image.ImageInfo) => { if(error) { console.log('getImageInfo failed.'); } else { @@ -1388,7 +1398,7 @@ getImageInfo(callback: AsyncCallback\): void **示例:** -```js +```ts imageSourceApi.getImageInfo((imageInfo : image.ImageInfo) => { console.log('Succeeded in obtaining the image information.'); }) @@ -1416,7 +1426,7 @@ getImageInfo(index?: number): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' imageSourceApi.getImageInfo(0) .then((imageInfo : image.ImageInfo) => { @@ -1449,7 +1459,7 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\ { console.log('Succeeded in getting the value of the specified attribute key of the image.'); @@ -1473,8 +1483,9 @@ getImageProperty(key:string, callback: AsyncCallback\): void **示例:** -```js -imageSourceApi.getImageProperty("BitsPerSample",(error, data : string) => { +```ts +import {BusinessError} from '@ohos.base' +imageSourceApi.getImageProperty("BitsPerSample",(error : BusinessError, data : string) => { if(error) { console.log('Failed to get the value of the specified attribute key of the image.'); } else { @@ -1501,9 +1512,10 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa **示例:** -```js +```ts +import {BusinessError} from '@ohos.base' let property : image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' } -imageSourceApi.getImageProperty("BitsPerSample",property,(error, data : string) => { +imageSourceApi.getImageProperty("BitsPerSample",property,(error : BusinessError, data : string) => { if(error) { console.log('Failed to get the value of the specified attribute key of the image.'); } else { @@ -1535,7 +1547,7 @@ modifyImageProperty(key: string, value: string): Promise\ **示例:** -```js +```ts imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => { const w : string = imageSourceApi.getImageProperty("ImageWidth"); console.info('w', w); @@ -1560,7 +1572,7 @@ modifyImageProperty(key: string, value: string, callback: AsyncCallback\): **示例:** -```js +```ts imageSourceApi.modifyImageProperty("ImageWidth", "120",() => {}) ``` @@ -1589,7 +1601,7 @@ updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number) **示例:** -```js +```ts const array : ArrayBuffer = new ArrayBuffer(100); imageSourceApi.updateData(array, false, 0, 10).then(data => { console.info('Succeeded in updating data.'); @@ -1617,7 +1629,7 @@ updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number, **示例:** -```js +```ts const array : ArrayBuffer = new ArrayBuffer(100); imageSourceApi.updateData(array, false, 0, 10,(error,data )=> { if(data !== undefined){ @@ -1648,7 +1660,7 @@ createPixelMap(options?: DecodingOptions): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' imageSourceApi.createPixelMap().then((pixelmap : image.PixelMap) => { console.log('Succeeded in creating pixelmap object through image decoding parameters.'); @@ -1673,8 +1685,9 @@ createPixelMap(callback: AsyncCallback\): void **示例:** -```js -imageSourceApi.createPixelMap((err, pixelmap : image.PixelMap) => { +```ts +import {BusinessError} from '@ohos.base' +imageSourceApi.createPixelMap((err : BusinessError, pixelmap : image.PixelMap) => { console.info('Succeeded in creating pixelmap object.'); }) ``` @@ -1696,7 +1709,7 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\): vo **示例:** -```js +```ts let decodingOptions : image.DecodingOptions = { sampleSize: 1, editable: true, @@ -1706,7 +1719,7 @@ let decodingOptions : image.DecodingOptions = { desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, index: 0 }; -imageSourceApi.createPixelMap(decodingOptions, pixelmap : image.PixelMap => { +imageSourceApi.createPixelMap(decodingOptions, (pixelmap : image.PixelMap) => { console.log('Succeeded in creating pixelmap object.'); }) ``` @@ -1745,7 +1758,7 @@ createPixelMapList(options?: DecodingOptions): Promise>; **示例:** -```js +```ts let decodeOpts : image.DecodingOptions = { sampleSize: 1, editable: true, @@ -1785,7 +1798,7 @@ createPixelMapList(callback: AsyncCallback>): void **示例:** -```js +```ts imageSourceApi.createPixelMapList( (pixelmaplist : Array) => { console.info('Succeeded in creating pixelmaplist object.'); }) @@ -1820,7 +1833,7 @@ createPixelMapList(options: DecodingOptions, callback: AsyncCallback>): void; **示例:** -```js +```ts imageSourceApi.getDelayTimeList( (delayTimes : Array) => { console.log('Succeeded in getting delay time.'); }); @@ -1900,7 +1913,7 @@ getDelayTimeList(): Promise>; **示例:** -```js +```ts let delayTimes : Array = imageSourceApi.getDelayTimeList(); ``` @@ -1934,7 +1947,7 @@ getFrameCount(callback: AsyncCallback\): void; **示例:** -```js +```ts imageSourceApi.getFrameCount( (frameCount : number) => { console.log('Succeeded in getting frame count.'); }); @@ -1970,7 +1983,7 @@ getFrameCount(): Promise\; **示例:** -```js +```ts let frameCount : number = imageSourceApi.getFrameCount(); ``` @@ -1990,7 +2003,7 @@ release(callback: AsyncCallback\): void **示例:** -```js +```ts imageSourceApi.release(() => { console.log('release succeeded.'); }) @@ -2012,7 +2025,7 @@ release(): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' imageSourceApi.release().then(()=>{ console.log('Succeeded in releasing the image source instance.'); @@ -2037,7 +2050,7 @@ createImagePacker(): ImagePacker **示例:** -```js +```ts const imagePackerApi : image.ImagePacker = image.createImagePacker(); ``` @@ -2071,7 +2084,7 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\ {}) @@ -2100,12 +2113,12 @@ packing(source: ImageSource, option: PackingOption): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' const imageSourceApi : image.ImageSource = image.createImageSource(0); let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 } imagePackerApi.packing(imageSourceApi, packOpts) - .then( data : ArrayBuffer => { + .then( (data : ArrayBuffer) => { console.log('packing succeeded.'); }).catch((error : BusinessError) => { console.log('packing failed.'); @@ -2130,13 +2143,13 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\ { +image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => { let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 } - imagePackerApi.packing(pixelmap, packOpts, data : ArrayBuffer => { + imagePackerApi.packing(pixelmap, packOpts, (data : ArrayBuffer) => { console.log('Succeeded in packing the image.'); }) }) @@ -2165,7 +2178,7 @@ packing(source: PixelMap, option: PackingOption): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 let bufferArr : Uint8Array = new Uint8Array(color); @@ -2173,7 +2186,7 @@ let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => { let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 } imagePackerApi.packing(pixelmap, packOpts) - .then( data : ArrayBuffer => { + .then( (data : ArrayBuffer) => { console.log('Succeeded in packing the image.'); }).catch((error : BusinessError) => { console.log('Failed to pack the image..'); @@ -2197,7 +2210,7 @@ release(callback: AsyncCallback\): void **示例:** -```js +```ts imagePackerApi.release(()=>{ console.log('Succeeded in releasing image packaging.'); }) @@ -2219,7 +2232,7 @@ release(): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' imagePackerApi.release().then(()=>{ console.log('Succeeded in releasing image packaging.'); @@ -2253,8 +2266,8 @@ createImageReceiver(width: number, height: number, format: number, capacity: num **示例:** -```js -var receiver image.ImageReceiver = image.createImageReceiver(8192, 8, 2000, 8); +```ts +let receiver : image.ImageReceiver = image.createImageReceiver(8192, 8, 2000, 8); ``` ## ImageReceiver9+ @@ -2289,8 +2302,9 @@ getReceivingSurfaceId(callback: AsyncCallback\): void **示例:** -```js -receiver.getReceivingSurfaceId((err, id : string) => { +```ts +import {BusinessError} from '@ohos.base' +receiver.getReceivingSurfaceId((err : BusinessError, id : string) => { if(err) { console.log('getReceivingSurfaceId failed.'); } else { @@ -2315,7 +2329,7 @@ getReceivingSurfaceId(): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' receiver.getReceivingSurfaceId().then( (id : string) => { console.log('getReceivingSurfaceId succeeded.'); @@ -2340,8 +2354,9 @@ readLatestImage(callback: AsyncCallback\): void **示例:** -```js -receiver.readLatestImage((err, img : image.Image) => { +```ts +import {BusinessError} from '@ohos.base' +receiver.readLatestImage((err : BusinessError, img : image.Image) => { if(err) { console.log('readLatestImage failed.'); } else { @@ -2366,7 +2381,7 @@ readLatestImage(): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' receiver.readLatestImage().then((img : image.Image) => { console.log('readLatestImage succeeded.'); @@ -2391,8 +2406,9 @@ readNextImage(callback: AsyncCallback\): void **示例:** -```js -receiver.readNextImage((err, img : image.Image) => { +```ts +import {BusinessError} from '@ohos.base' +receiver.readNextImage((err : BusinessError, img : image.Image) => { if(err) { console.log('readNextImage failed.'); } else { @@ -2417,7 +2433,7 @@ readNextImage(): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' receiver.readNextImage().then((img : image.Image) => { console.log('readNextImage succeeded.'); @@ -2443,7 +2459,7 @@ on(type: 'imageArrival', callback: AsyncCallback\): void **示例:** -```js +```ts receiver.on('imageArrival', () => {}) ``` @@ -2463,7 +2479,7 @@ release(callback: AsyncCallback\): void **示例:** -```js +```ts receiver.release(() => {}) ``` @@ -2483,7 +2499,7 @@ release(): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' receiver.release().then(() => { console.log('release succeeded.'); @@ -2517,8 +2533,8 @@ createImageCreator(width: number, height: number, format: number, capacity: numb **示例:** -```js -var creator : image.ImageCreator = image.createImageCreator(8192, 8, 4, 8); +```ts +let creator : image.ImageCreator = image.createImageCreator(8192, 8, 4, 8); ``` ## ImageCreator9+ @@ -2551,8 +2567,9 @@ dequeueImage(callback: AsyncCallback\): void **示例:** -```js -creator.dequeueImage((err, img : image.Image) => { +```ts +import {BusinessError} from '@ohos.base' +creator.dequeueImage((err : BusinessError, img : image.Image) => { if (err) { console.info('dequeueImage failed.'); } @@ -2576,7 +2593,7 @@ dequeueImage(): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' creator.dequeueImage().then((img : image.Image) => { console.info('dequeueImage succeeded.'); @@ -2602,19 +2619,20 @@ queueImage(interface: Image, callback: AsyncCallback\): void **示例:** -```js +```ts +import {BusinessError} from '@ohos.base' creator.dequeueImage().then((img : image.Image) => { //绘制图片 - img.getComponent(4).then(component : image.Component => { - var bufferArr : Uint8Array = new Uint8Array(component.byteBuffer); - for (var i = 0; i < bufferArr.length; i += 4) { + img.getComponent(4).then( (component : image.Component) => { + let bufferArr : Uint8Array = new Uint8Array(component.byteBuffer); + for (let i = 0; i < bufferArr.length; i += 4) { bufferArr[i] = 0; //B bufferArr[i + 1] = 0; //G bufferArr[i + 2] = 255; //R bufferArr[i + 3] = 255; //A } }) - creator.queueImage(img, (err) => { + creator.queueImage(img, (err : BusinessError) => { if (err) { console.info('queueImage failed: ' + err); } @@ -2646,13 +2664,13 @@ queueImage(interface: Image): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' creator.dequeueImage().then((img : image.Image) => { //绘制图片 img.getComponent(4).then(component : image.Component => { - var bufferArr : Uint8Array = new Uint8Array(component.byteBuffer); - for (var i = 0; i < bufferArr.length; i += 4) { + let bufferArr : Uint8Array = new Uint8Array(component.byteBuffer); + for (let i = 0; i < bufferArr.length; i += 4) { bufferArr[i] = 0; //B bufferArr[i + 1] = 0; //G bufferArr[i + 2] = 255; //R @@ -2685,8 +2703,9 @@ on(type: 'imageRelease', callback: AsyncCallback\): void **示例:** -```js -creator.on('imageRelease', (err) => { +```ts +import {BusinessError} from '@ohos.base' +creator.on('imageRelease', (err : BusinessError) => { if (err) { console.info('on faild' + err); } @@ -2710,8 +2729,9 @@ release(callback: AsyncCallback\): void **示例:** -```js -creator.release((err) => { +```ts +import {BusinessError} from '@ohos.base' +creator.release((err : BusinessError) => { if (err) { console.info('release failed: ' + err); } @@ -2734,7 +2754,7 @@ release(): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' creator.release().then(() => { console.info('release succeeded'); @@ -2774,8 +2794,9 @@ getComponent(componentType: ComponentType, callback: AsyncCallback\): **示例:** -```js -img.getComponent(4, (err, component : image.Component) => { +```ts +import {BusinessError} from '@ohos.base' +img.getComponent(4, (err : BusinessError, component : image.Component) => { if(err) { console.log('getComponent failed.'); } else { @@ -2806,7 +2827,7 @@ getComponent(componentType: ComponentType): Promise\ **示例:** -```js +```ts img.getComponent(4).then((component : image.Component) => { }) ``` @@ -2828,7 +2849,7 @@ release(callback: AsyncCallback\): void **示例:** -```js +```ts img.release(() =>{ console.log('release succeeded.'); }) @@ -2852,7 +2873,7 @@ release(): Promise\ **示例:** -```js +```ts import {BusinessError} from '@ohos.base' img.release().then(() =>{ console.log('release succeeded.');