未验证 提交 f9a0031f 编写于 作者: O openharmony_ci 提交者: Gitee

!23842 指南文档ArkTS适配

Merge pull request !23842 from 刘关鹏/master
...@@ -30,9 +30,10 @@ ...@@ -30,9 +30,10 @@
方法一:通过PixelMap进行编码。 方法一:通过PixelMap进行编码。
```ts ```ts
import {BusinessError} from '@ohos.base'
imagePackerApi.packing(pixelMap, packOpts).then( (data : ArrayBuffer) => { imagePackerApi.packing(pixelMap, packOpts).then( (data : ArrayBuffer) => {
// data 为打包获取到的文件流,写入文件保存即可得到一张图片 // data 为打包获取到的文件流,写入文件保存即可得到一张图片
}).catch(error => { }).catch((error : BusinessError) => {
console.error('Failed to pack the image. And the error is: ' + error); console.error('Failed to pack the image. And the error is: ' + error);
}) })
``` ```
...@@ -40,9 +41,10 @@ ...@@ -40,9 +41,10 @@
方法二:通过imageSource进行编码。 方法二:通过imageSource进行编码。
```ts ```ts
import {BusinessError} from '@ohos.base'
imagePackerApi.packing(imageSource, packOpts).then( (data : ArrayBuffer) => { imagePackerApi.packing(imageSource, packOpts).then( (data : ArrayBuffer) => {
// data 为打包获取到的文件流,写入文件保存即可得到一张图片 // data 为打包获取到的文件流,写入文件保存即可得到一张图片
}).catch(error => { }).catch((error : BusinessError) => {
console.error('Failed to pack the image. And the error is: ' + error); console.error('Failed to pack the image. And the error is: ' + error);
}) })
``` ```
...@@ -27,11 +27,12 @@ ...@@ -27,11 +27,12 @@
3. 读取并修改目标区域像素数据,写回原图。 3. 读取并修改目标区域像素数据,写回原图。
```ts ```ts
import {BusinessError} from '@ohos.base'
// 场景一:将读取的整张图像像素数据结果写入ArrayBuffer中 // 场景一:将读取的整张图像像素数据结果写入ArrayBuffer中
const readBuffer = new ArrayBuffer(pixelBytesNumber); const readBuffer = new ArrayBuffer(pixelBytesNumber);
pixelMap.readPixelsToBuffer(readBuffer).then(() => { pixelMap.readPixelsToBuffer(readBuffer).then(() => {
console.info('Succeeded in reading image pixel data.'); console.info('Succeeded in reading image pixel data.');
}).catch(error => { }).catch((error : BusinessError) => {
console.error('Failed to read image pixel data. And the error is: ' + error); console.error('Failed to read image pixel data. And the error is: ' + error);
}) })
...@@ -44,7 +45,7 @@ ...@@ -44,7 +45,7 @@
} }
pixelMap.readPixels(area).then(() => { pixelMap.readPixels(area).then(() => {
console.info('Succeeded in reading the image data in the area.'); console.info('Succeeded in reading the image data in the area.');
}).catch(error => { }).catch((error : BusinessError) => {
console.error('Failed to read the image data in the area. And the error is: ' + error); console.error('Failed to read the image data in the area. And the error is: ' + error);
}) })
......
...@@ -36,12 +36,13 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi ...@@ -36,12 +36,13 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => { image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => {
console.log('Succeeded in creating pixelmap.'); console.log('Succeeded in creating pixelmap.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('Failed to create pixelmap.'); console.log('Failed to create pixelmap.');
}) })
``` ```
...@@ -112,10 +113,11 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\<void> ...@@ -112,10 +113,11 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
const readBuffer : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const readBuffer : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
pixelmap.readPixelsToBuffer(readBuffer).then(() => { pixelmap.readPixelsToBuffer(readBuffer).then(() => {
console.log('Succeeded in reading image pixel data.'); //符合条件则进入 console.log('Succeeded in reading image pixel data.'); //符合条件则进入
}).catch(error => { }).catch((error : BusinessError) => {
console.log('Failed to read image pixel data.'); //不符合条件则进入 console.log('Failed to read image pixel data.'); //不符合条件则进入
}) })
``` ```
...@@ -171,6 +173,7 @@ readPixels(area: PositionArea): Promise\<void> ...@@ -171,6 +173,7 @@ readPixels(area: PositionArea): Promise\<void>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
const area : image.PositionArea = { const area : image.PositionArea = {
pixels: new ArrayBuffer(8), pixels: new ArrayBuffer(8),
offset: 0, offset: 0,
...@@ -179,7 +182,7 @@ const area : image.PositionArea = { ...@@ -179,7 +182,7 @@ const area : image.PositionArea = {
} }
pixelmap.readPixels(area).then(() => { pixelmap.readPixels(area).then(() => {
console.log('Succeeded in reading the image data in the area.'); //符合条件则进入 console.log('Succeeded in reading the image data in the area.'); //符合条件则进入
}).catch(error => { }).catch((error : BusinessError) => {
console.log('Failed to read the image data in the area.'); //不符合条件则进入 console.log('Failed to read the image data in the area.'); //不符合条件则进入
}) })
``` ```
...@@ -243,6 +246,7 @@ writePixels(area: PositionArea): Promise\<void> ...@@ -243,6 +246,7 @@ writePixels(area: PositionArea): Promise\<void>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
...@@ -264,7 +268,7 @@ image.createPixelMap(color, opts) ...@@ -264,7 +268,7 @@ image.createPixelMap(color, opts)
pixelmap.writePixels(area).then(() => { pixelmap.writePixels(area).then(() => {
console.info('Succeeded to write pixelmap into the specified area.'); console.info('Succeeded to write pixelmap into the specified area.');
}) })
}).catch(error => { }).catch((error : BusinessError) => {
console.log('error: ' + error); console.log('error: ' + error);
}) })
``` ```
...@@ -328,6 +332,7 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void> ...@@ -328,6 +332,7 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
for (var i = 0; i < bufferArr.length; i++) { for (var i = 0; i < bufferArr.length; i++) {
...@@ -335,7 +340,7 @@ for (var i = 0; i < bufferArr.length; i++) { ...@@ -335,7 +340,7 @@ for (var i = 0; i < bufferArr.length; i++) {
} }
pixelmap.writeBufferToPixels(color).then(() => { pixelmap.writeBufferToPixels(color).then(() => {
console.log("Succeeded in writing data from a buffer to a PixelMap."); console.log("Succeeded in writing data from a buffer to a PixelMap.");
}).catch((err) => { }).catch((error : BusinessError) => {
console.error("Failed to write data from a buffer to a PixelMap."); console.error("Failed to write data from a buffer to a PixelMap.");
}) })
``` ```
...@@ -1074,9 +1079,10 @@ release():Promise\<void> ...@@ -1074,9 +1079,10 @@ release():Promise\<void>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
pixelmap.release().then(() => { pixelmap.release().then(() => {
console.log('Succeeded in releasing pixelmap object.'); console.log('Succeeded in releasing pixelmap object.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('Failed to release pixelmap object.'); console.log('Failed to release pixelmap object.');
}) })
``` ```
...@@ -1411,10 +1417,11 @@ getImageInfo(index?: number): Promise\<ImageInfo> ...@@ -1411,10 +1417,11 @@ getImageInfo(index?: number): Promise\<ImageInfo>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
imageSourceApi.getImageInfo(0) imageSourceApi.getImageInfo(0)
.then((imageInfo : image.ImageInfo) => { .then((imageInfo : image.ImageInfo) => {
console.log('Succeeded in obtaining the image information.'); console.log('Succeeded in obtaining the image information.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('Failed to obtain the image information.'); console.log('Failed to obtain the image information.');
}) })
``` ```
...@@ -1642,9 +1649,10 @@ createPixelMap(options?: DecodingOptions): Promise\<PixelMap> ...@@ -1642,9 +1649,10 @@ createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
imageSourceApi.createPixelMap().then((pixelmap : image.PixelMap) => { imageSourceApi.createPixelMap().then((pixelmap : image.PixelMap) => {
console.log('Succeeded in creating pixelmap object through image decoding parameters.'); console.log('Succeeded in creating pixelmap object through image decoding parameters.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('Failed to create pixelmap object through image decoding parameters.'); console.log('Failed to create pixelmap object through image decoding parameters.');
}) })
``` ```
...@@ -2005,9 +2013,10 @@ release(): Promise\<void> ...@@ -2005,9 +2013,10 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
imageSourceApi.release().then(()=>{ imageSourceApi.release().then(()=>{
console.log('Succeeded in releasing the image source instance.'); console.log('Succeeded in releasing the image source instance.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('Failed to release the image source instance.'); console.log('Failed to release the image source instance.');
}) })
``` ```
...@@ -2092,12 +2101,13 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer> ...@@ -2092,12 +2101,13 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
const imageSourceApi : image.ImageSource = image.createImageSource(0); const imageSourceApi : image.ImageSource = image.createImageSource(0);
let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 } let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts) imagePackerApi.packing(imageSourceApi, packOpts)
.then( data : ArrayBuffer => { .then( data : ArrayBuffer => {
console.log('packing succeeded.'); console.log('packing succeeded.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('packing failed.'); console.log('packing failed.');
}) })
``` ```
...@@ -2156,6 +2166,7 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> ...@@ -2156,6 +2166,7 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
...@@ -2164,7 +2175,7 @@ image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => { ...@@ -2164,7 +2175,7 @@ image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => {
imagePackerApi.packing(pixelmap, packOpts) imagePackerApi.packing(pixelmap, packOpts)
.then( data : ArrayBuffer => { .then( data : ArrayBuffer => {
console.log('Succeeded in packing the image.'); console.log('Succeeded in packing the image.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('Failed to pack the image..'); console.log('Failed to pack the image..');
}) })
}) })
...@@ -2209,9 +2220,10 @@ release(): Promise\<void> ...@@ -2209,9 +2220,10 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
imagePackerApi.release().then(()=>{ imagePackerApi.release().then(()=>{
console.log('Succeeded in releasing image packaging.'); console.log('Succeeded in releasing image packaging.');
}).catch((error)=>{ }).catch((error : BusinessError)=>{
console.log('Failed to release image packaging.'); console.log('Failed to release image packaging.');
}) })
``` ```
...@@ -2304,9 +2316,10 @@ getReceivingSurfaceId(): Promise\<string> ...@@ -2304,9 +2316,10 @@ getReceivingSurfaceId(): Promise\<string>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
receiver.getReceivingSurfaceId().then( (id : string) => { receiver.getReceivingSurfaceId().then( (id : string) => {
console.log('getReceivingSurfaceId succeeded.'); console.log('getReceivingSurfaceId succeeded.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('getReceivingSurfaceId failed.'); console.log('getReceivingSurfaceId failed.');
}) })
``` ```
...@@ -2354,9 +2367,10 @@ readLatestImage(): Promise\<Image> ...@@ -2354,9 +2367,10 @@ readLatestImage(): Promise\<Image>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
receiver.readLatestImage().then((img : image.Image) => { receiver.readLatestImage().then((img : image.Image) => {
console.log('readLatestImage succeeded.'); console.log('readLatestImage succeeded.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('readLatestImage failed.'); console.log('readLatestImage failed.');
}) })
``` ```
...@@ -2404,9 +2418,10 @@ readNextImage(): Promise\<Image> ...@@ -2404,9 +2418,10 @@ readNextImage(): Promise\<Image>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
receiver.readNextImage().then((img : image.Image) => { receiver.readNextImage().then((img : image.Image) => {
console.log('readNextImage succeeded.'); console.log('readNextImage succeeded.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('readNextImage failed.'); console.log('readNextImage failed.');
}) })
``` ```
...@@ -2469,9 +2484,10 @@ release(): Promise\<void> ...@@ -2469,9 +2484,10 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
receiver.release().then(() => { receiver.release().then(() => {
console.log('release succeeded.'); console.log('release succeeded.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('release failed.'); console.log('release failed.');
}) })
``` ```
...@@ -2561,9 +2577,10 @@ dequeueImage(): Promise\<Image> ...@@ -2561,9 +2577,10 @@ dequeueImage(): Promise\<Image>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
creator.dequeueImage().then((img : image.Image) => { creator.dequeueImage().then((img : image.Image) => {
console.info('dequeueImage succeeded.'); console.info('dequeueImage succeeded.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('dequeueImage failed: ' + error); console.log('dequeueImage failed: ' + error);
}) })
``` ```
...@@ -2630,6 +2647,7 @@ queueImage(interface: Image): Promise\<void> ...@@ -2630,6 +2647,7 @@ queueImage(interface: Image): Promise\<void>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
creator.dequeueImage().then((img : image.Image) => { creator.dequeueImage().then((img : image.Image) => {
//绘制图片 //绘制图片
img.getComponent(4).then(component : image.Component => { img.getComponent(4).then(component : image.Component => {
...@@ -2643,7 +2661,7 @@ creator.dequeueImage().then((img : image.Image) => { ...@@ -2643,7 +2661,7 @@ creator.dequeueImage().then((img : image.Image) => {
}) })
creator.queueImage(img).then(() => { creator.queueImage(img).then(() => {
console.info('queueImage succeeded.'); console.info('queueImage succeeded.');
}).catch(error => { }).catch((error : BusinessError) => {
console.info('queueImage failed: ' + error); console.info('queueImage failed: ' + error);
}) })
}) })
...@@ -2717,9 +2735,10 @@ release(): Promise\<void> ...@@ -2717,9 +2735,10 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
creator.release().then(() => { creator.release().then(() => {
console.info('release succeeded'); console.info('release succeeded');
}).catch(error => { }).catch((error : BusinessError) => {
console.info('release failed'); console.info('release failed');
}) })
``` ```
...@@ -2834,9 +2853,10 @@ release(): Promise\<void> ...@@ -2834,9 +2853,10 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```js
import {BusinessError} from '@ohos.base'
img.release().then(() =>{ img.release().then(() =>{
console.log('release succeeded.'); console.log('release succeeded.');
}).catch(error => { }).catch((error : BusinessError) => {
console.log('release failed.'); console.log('release failed.');
}) })
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册