提交 2b3d71dd 编写于 作者: R renhongwei

fix image docs

Signed-off-by: Nrenhongwei <renhongwei9@huawei.com>
上级 30bff42a
...@@ -19,20 +19,17 @@ const color = new ArrayBuffer(96); // 用于存放图像像素数据 ...@@ -19,20 +19,17 @@ 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);
let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } }
image.createPixelMap(color, opts, (err, pixelmap) => { image.createPixelMap(color, opts, (err, pixelmap) => {
console.log('Succeeded in creating pixelmap.'); console.log('Succeeded in creating pixelmap.');
})
// 用于读像素 // 用于读像素
const area = { const area = {
pixels: new ArrayBuffer(8), pixels: new ArrayBuffer(8),
offset: 0, offset: 0,
stride: 8, 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,() => { pixelmap.readPixels(area,() => {
var bufferArr = new Uint8Array(area.pixels); var bufferArr = new Uint8Array(area.pixels);
var res = true; var res = true;
for (var i = 0; i < bufferArr.length; i++) { for (var i = 0; i < bufferArr.length; i++) {
...@@ -45,11 +42,11 @@ pixelmap.readPixels(area,() => { ...@@ -45,11 +42,11 @@ pixelmap.readPixels(area,() => {
} }
} }
} }
}) })
// 用于存像素 // 用于存像素
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);
var res = true; var res = true;
for (var i = 0; i < bufferArr.length; i++) { for (var i = 0; i < bufferArr.length; i++) {
...@@ -61,10 +58,10 @@ pixelmap.readPixelsToBuffer(readBuffer,() => { ...@@ -61,10 +58,10 @@ pixelmap.readPixelsToBuffer(readBuffer,() => {
} }
} }
} }
}) })
// 用于写像素 // 用于写像素
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,() => {
var readArr = new Uint8Array(readArea.pixels); var readArr = new Uint8Array(readArea.pixels);
...@@ -79,10 +76,11 @@ pixelmap.writePixels(area,() => { ...@@ -79,10 +76,11 @@ pixelmap.writePixels(area,() => {
} }
} }
}) })
}) })
// 用于写像素到缓冲区 const writeColor = new ArrayBuffer(96); //图像像素数据
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 (() => {
var bufferArr = new Uint8Array(readBuffer); var bufferArr = new Uint8Array(readBuffer);
...@@ -97,34 +95,35 @@ pixelmap.writeBufferToPixels(writeColor).then(() => { ...@@ -97,34 +95,35 @@ pixelmap.writeBufferToPixels(writeColor).then(() => {
} }
} }
}) })
}) })
// 用于获取图片信息 // 用于获取图片信息
pixelmap.getImageInfo((error, imageInfo) => { pixelmap.getImageInfo((error, imageInfo) => {
if (imageInfo !== null) { if (imageInfo !== null) {
console.log('Succeeded in getting imageInfo'); console.log('Succeeded in getting imageInfo');
} }
}) })
// 用于释放pixelmap // 用于释放pixelmap
pixelmap.release(()=>{ pixelmap.release(()=>{
console.log('Succeeded in releasing pixelmap'); console.log('Succeeded in releasing pixelmap');
})
}) })
// 用于创建imagesource(uri) // 用于创建imagesource(uri)
let path = '/data/local/tmp/test.jpg'; let path = '/data/local/tmp/test.jpg';
const imageSourceApi = image.createImageSource(path); const imageSourceApi1 = image.createImageSource(path);
// 用于创建imagesource(fd) // 用于创建imagesource(fd)
let fd = 29; let fd = 29;
const imageSourceApi = image.createImageSource(fd); const imageSourceApi2 = image.createImageSource(fd);
// 用于创建imagesource(data) // 用于创建imagesource(data)
const data = new ArrayBuffer(96); const data = new ArrayBuffer(96);
const imageSourceApi = image.createImageSource(data); const imageSourceApi3 = image.createImageSource(data);
// 用于释放imagesource // 用于释放imagesource
imageSourceApi.release(() => { imageSourceApi3.release(() => {
console.log('Succeeded in releasing imagesource'); console.log('Succeeded in releasing imagesource');
}) })
...@@ -167,30 +166,22 @@ imageSourceApi.createPixelMap(decodingOptions, (err, pixelmap) => { ...@@ -167,30 +166,22 @@ imageSourceApi.createPixelMap(decodingOptions, (err, pixelmap) => {
// 用于promise创建pixelmap // 用于promise创建pixelmap
imageSourceApi.createPixelMap().then(pixelmap => { imageSourceApi.createPixelMap().then(pixelmap => {
console.log('Succeeded in creating pixelmap.'); console.log('Succeeded in creating pixelmap.');
})
// 函数调用发生异常时,捕捉错误信息 // 用于获取像素每行字节数
catch(error => { var num = pixelmap.getBytesNumberPerRow();
console.log('Failed in creating pixelmap.' + error);
})
// 用于获取像素每行字节数 // 用于获取像素总字节数
var num = pixelmap.getBytesNumberPerRow(); var pixelSize = pixelmap.getPixelBytesNumber();
// 用于获取像素总字节数 // 用于获取pixelmap信息
var pixelSize = pixelmap.getPixelBytesNumber(); pixelmap.getImageInfo().then( imageInfo => {});
// 用于获取pixelmap信息 // 用于释放pixelmap
pixelmap.getImageInfo().then( imageInfo => {}); pixelmap.release(()=>{
// 用于释放pixelmap
pixelmap.release(()=>{
console.log('Succeeded in releasing pixelmap'); console.log('Succeeded in releasing pixelmap');
}) })
}).catch(error => {
// 用于捕捉释放失败信息 console.log('Failed in creating pixelmap.' + error);
catch(error => {
console.log('Failed in releasing pixelmap.' + error);
}) })
``` ```
...@@ -216,7 +207,7 @@ if (imagePackerApi == null) { ...@@ -216,7 +207,7 @@ if (imagePackerApi == null) {
} }
// 如果创建imagepacker成功,则设置编码参数 // 如果创建imagepacker成功,则设置编码参数
let packOpts = { format:["image/jpeg"], // 支持编码的格式为jpg let packOpts = { format:"image/jpeg", // 支持编码的格式为jpg
quality:98 } // 图片质量0-100 quality:98 } // 图片质量0-100
// 用于编码 // 用于编码
...@@ -233,8 +224,9 @@ imageSourceApi.getImageInfo((err, imageInfo) => { ...@@ -233,8 +224,9 @@ imageSourceApi.getImageInfo((err, imageInfo) => {
console.log('Succeeded in getting imageInfo'); console.log('Succeeded in getting imageInfo');
}) })
const array = new ArrayBuffer(100); //增量数据
// 用于更新增量数据 // 用于更新增量数据
imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error, data)=> {}) imageSourceApi.updateData(array, false, 0, 10,(error, data)=> {})
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册