未验证 提交 afee8972 编写于 作者: R robert-han 提交者: Gitee

update zh-cn/application-dev/media/image.md.

注释使用不当
Signed-off-by: N韩琰 <yanhanj@isoftstone.com>
上级 6c4b2a87
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
包含流程:创建实例、读取图片信息、读写pixelmap、更新数据、打包像素、释放资源等流程。 包含流程:创建实例、读取图片信息、读写pixelmap、更新数据、打包像素、释放资源等流程。
```js ```js
const color = new ArrayBuffer(96);//用于存放图像像素数据 const color = new ArrayBuffer(96); // 用于存放图像像素数据
let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } } //图像像素数据 let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } } // 图像像素数据
//创建pixelmap对象 // 创建pixelmap对象
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } } let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } }
image.createPixelMap(color, opts, pixelmap => { image.createPixelMap(color, opts, pixelmap => {
...@@ -26,7 +26,7 @@ let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { ...@@ -26,7 +26,7 @@ let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: {
console.info('TC_001-1 success'); console.info('TC_001-1 success');
done(); done();
}) })
//用于读像素 // 用于读像素
pixelmap.readPixels(area,(data) => { pixelmap.readPixels(area,(data) => {
if(data !== null) { if(data !== null) {
var bufferArr = new Uint8Array(area.pixels); var bufferArr = new Uint8Array(area.pixels);
...@@ -44,7 +44,7 @@ pixelmap.readPixels(area,(data) => { ...@@ -44,7 +44,7 @@ pixelmap.readPixels(area,(data) => {
} }
} }
//用于存像素 // 用于存像素
const readBuffer = new ArrayBuffer(96); const readBuffer = new ArrayBuffer(96);
pixelmap.readPixelsToBuffer(readBuffer,() => { pixelmap.readPixelsToBuffer(readBuffer,() => {
var bufferArr = new Uint8Array(readBuffer); var bufferArr = new Uint8Array(readBuffer);
...@@ -61,7 +61,7 @@ for (var i = 0; i < bufferArr.length; i++) { ...@@ -61,7 +61,7 @@ for (var i = 0; i < bufferArr.length; i++) {
} }
} }
//用于写像素 // 用于写像素
pixelmap.writePixels(area,() => { pixelmap.writePixels(area,() => {
const readArea = { pixels: new ArrayBuffer(20), offset: 0, stride: 8, region: { size: { height: 1, width: 2 }, x: 0, y: 0 }} const readArea = { pixels: new ArrayBuffer(20), offset: 0, stride: 8, region: { size: { height: 1, width: 2 }, x: 0, y: 0 }}
pixelmap.readPixels(readArea,() => { pixelmap.readPixels(readArea,() => {
...@@ -79,7 +79,7 @@ pixelmap.writePixels(area,() => { ...@@ -79,7 +79,7 @@ pixelmap.writePixels(area,() => {
} }
} }
//用于写像素到缓冲区 // 用于写像素到缓冲区
pixelmap.writeBufferToPixels(writeColor).then(() => { pixelmap.writeBufferToPixels(writeColor).then(() => {
const readBuffer = new ArrayBuffer(96); const readBuffer = new ArrayBuffer(96);
pixelmap.readPixelsToBuffer(readBuffer).then (() => { pixelmap.readPixelsToBuffer(readBuffer).then (() => {
...@@ -97,7 +97,7 @@ pixelmap.writeBufferToPixels(writeColor).then(() => { ...@@ -97,7 +97,7 @@ pixelmap.writeBufferToPixels(writeColor).then(() => {
} }
} }
//用于获取图片信息 // 用于获取图片信息
pixelmap.getImageInfo( imageInfo => { pixelmap.getImageInfo( imageInfo => {
if (imageInfo !== null) { if (imageInfo !== null) {
console.info('TC_024-1 imageInfo is ready'); console.info('TC_024-1 imageInfo is ready');
...@@ -108,29 +108,29 @@ pixelmap.getImageInfo( imageInfo => { ...@@ -108,29 +108,29 @@ pixelmap.getImageInfo( imageInfo => {
} }
}) })
//用于释放pixelmap // 用于释放pixelmap
pixelmap.release(()=>{ pixelmap.release(()=>{
expect(true).assertTrue(); expect(true).assertTrue();
console.log('TC_027-1 suc'); console.log('TC_027-1 suc');
done(); done();
}) })
//用于创建imagesource(uri) // 用于创建imagesource(uri)
const imageSourceApi = image.createImageSource(path);//'/data/local/tmp/test.jpg' const imageSourceApi = image.createImageSource(path); // '/data/local/tmp/test.jpg'
//用于创建imagesource(fd) // 用于创建imagesource(fd)
const imageSourceApi = image.createImageSource(29); const imageSourceApi = image.createImageSource(29);
//用于创建imagesource(data) // 用于创建imagesource(data)
const data = new ArrayBuffer(96); const data = new ArrayBuffer(96);
const imageSourceApi = image.createImageSource(data); const imageSourceApi = image.createImageSource(data);
//用于释放imagesource // 用于释放imagesource
imageSourceApi.release(() => { imageSourceApi.release(() => {
console.info('TC_044-1 Success'); console.info('TC_044-1 Success');
}) })
//用于编码 // 用于编码
const imagePackerApi = image.createImagePacker(); const imagePackerApi = image.createImagePacker();
imagePackerApi.packing(imageSourceApi, packOpts, data => { imagePackerApi.packing(imageSourceApi, packOpts, data => {
console.info('TC_062-1 finished'); console.info('TC_062-1 finished');
...@@ -138,30 +138,30 @@ imagePackerApi.packing(imageSourceApi, packOpts, data => { ...@@ -138,30 +138,30 @@ imagePackerApi.packing(imageSourceApi, packOpts, data => {
done(); done();
}) })
//用于释放imagepacker // 用于释放imagepacker
imagePackerApi.release(); imagePackerApi.release();
``` ```
### 解码场景 ### 解码场景
```js ```js
/data/local/tmp/test.jpg //设置创建imagesource的路径 /data/local/tmp/test.jpg // 设置创建imagesource的路径
//用路径创建imagesource // 用路径创建imagesource
const imageSourceApi = image.createImageSource(path);//'/data/local/tmp/test.jpg' const imageSourceApi = image.createImageSource(path); // '/data/local/tmp/test.jpg'
//设置参数 // 设置参数
let decodingOptions = { let decodingOptions = {
sampleSize:1,//缩略图采样大小 sampleSize:1, // 缩略图采样大小
editable: true, //是否可编辑 editable: true, // 是否可编辑
desiredSize:{ width:1, height:2},//期望输出大小 desiredSize:{ width:1, height:2}, // 期望输出大小
rotateDegrees:10,//旋转角度 rotateDegrees:10, // 旋转角度
desiredPixelFormat:2,//解码的像素格式 desiredPixelFormat:2, // 解码的像素格式
desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },//解码的区域 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, // 解码的区域
index:0//图片序号 index:0 // 图片序号
}; };
//用于回调方式创建pixelmap // 用于回调方式创建pixelmap
imageSourceApi.createPixelMap(decodingOptions, pixelmap => { imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
console.info('TC_050 createPixelMap '); console.info('TC_050 createPixelMap ');
expect(pixelmap !== null ).assertTrue(); expect(pixelmap !== null ).assertTrue();
...@@ -169,49 +169,49 @@ imageSourceApi.createPixelMap(decodingOptions, pixelmap => { ...@@ -169,49 +169,49 @@ imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
}) })
} }
//用于promise创建pixelmap // 用于promise创建pixelmap
imageSourceApi.createPixelMap().then(pixelmap => { imageSourceApi.createPixelMap().then(pixelmap => {
console.info('TC_050-11 createPixelMap '); console.info('TC_050-11 createPixelMap ');
expect(pixelmap !== null ).assertTrue(); expect(pixelmap !== null ).assertTrue();
done(); done();
}) })
//函数调用发生异常时,捕捉错误信息 // 函数调用发生异常时,捕捉错误信息
catch(error => { catch(error => {
console.log('TC_050-11 error: ' + error); console.log('TC_050-11 error: ' + error);
expect().assertFail(); expect().assertFail();
done(); done();
}) })
//用于获取像素每行字节数 // 用于获取像素每行字节数
pixelmap.getBytesNumberPerRow( num => { pixelmap.getBytesNumberPerRow( num => {
console.info('TC_025-1 num is ' + num); console.info('TC_025-1 num is ' + num);
expect(num == expectNum).assertTrue(); expect(num == expectNum).assertTrue();
done(); done();
}) })
//用于获取像素总字节数 // 用于获取像素总字节数
pixelmap.getPixelBytesNumber(num => { pixelmap.getPixelBytesNumber(num => {
console.info('TC_026-1 num is ' + num); console.info('TC_026-1 num is ' + num);
expect(num == expectNum).assertTrue(); expect(num == expectNum).assertTrue();
done(); done();
}) })
//用于获取pixelmap信息 // 用于获取pixelmap信息
pixelmap.getImageInfo( imageInfo => {}) pixelmap.getImageInfo( imageInfo => {})
//用于打印获取失败信息 // 用于打印获取失败信息
console.info('TC_024-1 imageInfo is empty'); console.info('TC_024-1 imageInfo is empty');
expect(false).assertTrue() expect(false).assertTrue()
//用于释放pixelmap // 用于释放pixelmap
pixelmap.release(()=>{ pixelmap.release(()=>{
expect(true).assertTrue(); expect(true).assertTrue();
console.log('TC_027-1 suc'); console.log('TC_027-1 suc');
done(); done();
}) })
//用于捕捉释放失败信息 // 用于捕捉释放失败信息
catch(error => { catch(error => {
console.log('TC_027-1 error: ' + error); console.log('TC_027-1 error: ' + error);
expect().assertFail(); expect().assertFail();
...@@ -222,33 +222,33 @@ catch(error => { ...@@ -222,33 +222,33 @@ catch(error => {
### 编码场景 ### 编码场景
```js ```js
/data/local/tmp/test.png //设置创建imagesource的路径 /data/local/tmp/test.png // 设置创建imagesource的路径
//用于设置imagesource // 用于设置imagesource
const imageSourceApi = image.createImageSource(path);//'/data/local/tmp/test.png' const imageSourceApi = image.createImageSource(path); // '/data/local/tmp/test.png'
//如果创建imagesource失败,打印错误信息 // 如果创建imagesource失败,打印错误信息
if (imageSourceApi == null) { if (imageSourceApi == null) {
console.info('TC_062 create image source failed'); console.info('TC_062 create image source failed');
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} }
//如果创建imagesource成功,则创建imagepacker // 如果创建imagesource成功,则创建imagepacker
const imagePackerApi = image.createImagePacker(); const imagePackerApi = image.createImagePacker();
//如果创建失败,打印错误信息 // 如果创建失败,打印错误信息
if (imagePackerApi == null) { if (imagePackerApi == null) {
console.info('TC_062 create image packer failed'); console.info('TC_062 create image packer failed');
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} }
//如果创建imagepacker成功,则设置编码参数 // 如果创建imagepacker成功,则设置编码参数
let packOpts = { format:["image/jpeg"], //支持编码的格式为jpg let packOpts = { format:["image/jpeg"], // 支持编码的格式为jpg
quality:98 }//图片质量0-100 quality:98 } // 图片质量0-100
//用于编码 // 用于编码
imagePackerApi.packing(imageSourceApi, packOpts) imagePackerApi.packing(imageSourceApi, packOpts)
.then( data => { .then( data => {
console.info('TC_062 finished'); console.info('TC_062 finished');
...@@ -256,17 +256,17 @@ imagePackerApi.packing(imageSourceApi, packOpts) ...@@ -256,17 +256,17 @@ imagePackerApi.packing(imageSourceApi, packOpts)
done(); done();
}) })
//编码完成,释放imagepacker // 编码完成,释放imagepacker
imagePackerApi.release(); imagePackerApi.release();
//用于获取imagesource信息 // 用于获取imagesource信息
imageSourceApi.getImageInfo(imageInfo => { imageSourceApi.getImageInfo(imageInfo => {
console.info('TC_045 imageInfo'); console.info('TC_045 imageInfo');
expect(imageInfo !== null).assertTrue(); expect(imageInfo !== null).assertTrue();
done(); done();
}) })
//用于更新增量数据 // 用于更新增量数据
imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error,data )=> {}) imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error,data )=> {})
``` ```
...@@ -278,22 +278,22 @@ imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error,data )=> {}) ...@@ -278,22 +278,22 @@ imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error,data )=> {})
```js ```js
public async init(surfaceId: any) { public async init(surfaceId: any) {
//服务端代码,创建ImageReceiver // 服务端代码,创建ImageReceiver
var receiver = image.createImageReceiver(8 * 1024, 8, image.ImageFormat.JPEG, 1); var receiver = image.createImageReceiver(8 * 1024, 8, image.ImageFormat.JPEG, 1);
//获取Surface ID // 获取Surface ID
var surfaceId = await receiver.getReceivingSurfaceId(); var surfaceId = await receiver.getReceivingSurfaceId();
//注册Surface的监听,在suface的buffer准备好后触发 // 注册Surface的监听,在suface的buffer准备好后触发
receiver.on('imageArrival', () => { receiver.on('imageArrival', () => {
//去获取Surface中最新的buffer // 去获取Surface中最新的buffer
receiver.readNextImage((err, img) => { receiver.readNextImage((err, img) => {
img.getComponent(4, (err, component) => { img.getComponent(4, (err, component) => {
//消费component.byteBuffer,例如:将buffer内容保存成图片。 // 消费component.byteBuffer,例如:将buffer内容保存成图片。
}) })
}) })
}) })
//调用Camera方法将surfaceId传递给Camera。camera会通过surfaceId获取surface,并生产出surface buffer。 // 调用Camera方法将surfaceId传递给Camera。camera会通过surfaceId获取surface,并生产出surface buffer。
} }
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册