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

!23447 示例代码整改

Merge pull request !23447 from 朱静茹/master
......@@ -39,8 +39,8 @@
```ts
// Stage模型参考如下代码
const context : Context = getContext(this);
const filePath : string = context.cacheDir + '/test.jpg';
const context = getContext(this);
const filePath = context.cacheDir + '/test.jpg';
const file : File = fs.openSync(filePath, fs.OpenMode.READ_WRITE);
const fd : number = file?.fd;
```
......@@ -60,7 +60,7 @@
// Stage模型
const context : Context = getContext(this);
// 获取resourceManager资源管理器
const resourceMgr : ResourceManager = context.resourceManager;
const resourceMgr : resmgr.ResourceManager = context.resourceManager;
```
```ts
......@@ -73,7 +73,7 @@
不同模型获取资源管理器的方式不同,获取资源管理器后,再调用resourceMgr.getRawFileContent()获取资源文件的ArrayBuffer。
```ts
const fileData : Content = await resourceMgr.getRawFileContent('test.jpg');
const fileData : void = await resourceMgr.getRawFileContent('test.jpg');
// 获取图片的ArrayBuffer
const buffer = fileData.buffer;
```
......@@ -126,13 +126,13 @@
```ts
const context : Context = getContext(this);
// 获取resourceManager资源管理
const resourceMgr : ResourceManager = context.resourceManager;
const resourceMgr : resmgr.ResourceManager = context.resourceManager;
```
2. 获取rawfile文件夹下test.jpg的ArrayBuffer。
```ts
const fileData : Content = await resourceMgr.getRawFileContent('test.jpg');
const fileData : void = await resourceMgr.getRawFileContent('test.jpg');
// 获取图片的ArrayBuffer
const buffer = fileData.buffer;
```
......@@ -140,7 +140,7 @@
3. 创建imageSource。
```ts
const imageSource : ImageSource = image.createImageSource(buffer);
const imageSource : resmgr.ImageSource = image.createImageSource(buffer);
```
4. 创建PixelMap。
......
......@@ -20,7 +20,11 @@
format为图像的编码格式;quality为图像质量,范围从0-100,100为最佳质量。
```ts
let packOpts : Context = { format:"image/jpeg", quality:98 };
class PackOpts {
format : string = ""
quality : number = 0
}
let packOpts : PackOpts = { format:"image/jpeg", quality:98 };
```
3. [创建PixelMap对象或创建ImageSource](image-decoding.md)对象。
......@@ -30,9 +34,9 @@
方法一:通过PixelMap进行编码。
```ts
imagePackerApi.packing(pixelMap : PixelMap, packOpts).then( data => {
imagePackerApi.packing(pixelMap : PixelMap, packOpts : PackingOption).then( data => {
// data 为打包获取到的文件流,写入文件保存即可得到一张图片
}).catch(error : void => {
}).catch(error => {
console.error('Failed to pack the image. And the error is: ' + error);
})
```
......@@ -40,9 +44,9 @@
方法二:通过imageSource进行编码。
```ts
imagePackerApi.packing(imageSource, packOpts).then( data => {
imagePackerApi.packing(imageSource : ImageSource, packOpts : PackingOption).then( data => {
// data 为打包获取到的文件流,写入文件保存即可得到一张图片
}).catch(error : void => {
}).catch(error => {
console.error('Failed to pack the image. And the error is: ' + error);
})
```
......@@ -40,7 +40,7 @@
pixels: new ArrayBuffer(8),
offset: 0,
stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
region: { size : { height: 1, width: 2 }, x: 0, y: 0 }
}
pixelMap.readPixels(area).then(() => {
console.info('Succeeded in reading the image data in the area.');
......
......@@ -37,7 +37,7 @@ EXIF信息的读取与编辑相关API的详细介绍请参见[API参考](../refe
// 编辑EXIF信息
imageSource.modifyImageProperty('ImageWidth', '120').then(() => {
const width : number = imageSource.getImageProperty("ImageWidth");
const width : Promise<string> = imageSource.getImageProperty("ImageWidth");
console.info('The new imageWidth is ' + width);
})
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册