提交 3ece16bf 编写于 作者: W wusongqing

update docs against 5094+6489+5657

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 eda2f5ff
...@@ -15,19 +15,19 @@ For details about the APIs, see [Image Processing](../reference/apis/js-apis-ima ...@@ -15,19 +15,19 @@ For details about the APIs, see [Image Processing](../reference/apis/js-apis-ima
The full process includes creating an instance, reading image information, reading and writing pixel maps, updating data, packaging pixels, and releasing resources. The full process includes creating an instance, reading image information, reading and writing pixel maps, updating data, packaging pixels, and releasing resources.
```js ```js
const Color = new ArrayBuffer(96); // Create a buffer to store image pixel data. const color = new ArrayBuffer(96); // Create a buffer to store image pixel data.
let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } } // Image pixel data. let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } } // Image pixel data.
// Create a PixelMap object. // Create a PixelMap object.
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 => {
expect(pixelmap !== null).assertTrue(); expect(pixelmap !== null).assertTrue();
console.info('TC_001-1 success'); console.info('TC_001-1 success');
done(); done();
}) })
// Read pixels. // Read pixels.
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);
var res = true; var res = true;
...@@ -50,39 +50,39 @@ pixelmap.readPixelsToBuffer(readBuffer,() => { ...@@ -50,39 +50,39 @@ 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++) {
if(res) { if(res) {
if (bufferArr[i] !== 0) { if (bufferArr[i] !== 0) {
res = false; res = false;
console.info('TC_020-1 Success'); console.info('TC_020-1 Success');
expect(true).assertTrue(); expect(true).assertTrue();
done(); done();
break; break;
} }
}
} }
}
// Write pixels. // Write pixels.
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);
var res = true; var res = true;
for (var i = 0; i < readArr.length; i++) { for (var i = 0; i < readArr.length; i++) {
if(res) { if(res) {
if (readArr[i] !== 0) { if (readArr[i] !== 0) {
res = false; res = false;
console.info('TC_022-1 Success'); console.info('TC_022-1 Success');
expect(true).assertTrue(); expect(true).assertTrue();
done(); done();
break; break;
} }
}
} }
}
// Write pixels to the buffer. // Write pixels to the buffer.
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);
var res = true; var res = true;
for (var i = 0; i < bufferArr.length; i++) { for (var i = 0; i < bufferArr.length; i++) {
...@@ -95,18 +95,18 @@ pixelmap.writePixels(area,() => { ...@@ -95,18 +95,18 @@ pixelmap.writePixels(area,() => {
break; break;
} }
} }
} }
// Obtain image information. // Obtain image information.
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');
expect(imageInfo.size.height == 4).assertTrue(); expect(imageInfo.size.height == 4).assertTrue();
expect(imageInfo.size.width == 6).assertTrue(); expect(imageInfo.size.width == 6).assertTrue();
expect(imageInfo.pixelFormat == 4).assertTrue(); expect(imageInfo.pixelFormat == 4).assertTrue();
done(); done();
} }
}) })
// Release the PixelMap object. // Release the PixelMap object.
pixelmap.release(()=>{ pixelmap.release(()=>{
...@@ -116,7 +116,7 @@ pixelmap.release(()=>{ ...@@ -116,7 +116,7 @@ pixelmap.release(()=>{
}) })
// Create an image source (uri). // Create an image source (uri).
const imageSourceApi = image.createImageSource(path);//'/data/local/tmp/test.jpg' const imageSourceApi = image.createImageSource(path); // '/data/local/tmp/test.jpg'
// Create an image source (fd). // Create an image source (fd).
const imageSourceApi = image.createImageSource(29); const imageSourceApi = image.createImageSource(29);
...@@ -136,7 +136,7 @@ imagePackerApi.packing(imageSourceApi, packOpts, data => { ...@@ -136,7 +136,7 @@ imagePackerApi.packing(imageSourceApi, packOpts, data => {
console.info('TC_062-1 finished'); console.info('TC_062-1 finished');
expect(data !== null).assertTrue(); expect(data !== null).assertTrue();
done(); done();
}) })
// Release the ImagePacker object. // Release the ImagePacker object.
imagePackerApi.release(); imagePackerApi.release();
...@@ -148,7 +148,7 @@ imagePackerApi.release(); ...@@ -148,7 +148,7 @@ imagePackerApi.release();
/data/local/tmp/test.jpg // Set the path for creating an image source. /data/local/tmp/test.jpg // Set the path for creating an image source.
// Create an image source using a path. // Create an image source using a path.
const imageSourceApi = image.createImageSource(path);//'/data/local/tmp/test.jpg' const imageSourceApi = image.createImageSource(path); // '/data/local/tmp/test.jpg'
// Set parameters. // Set parameters.
let decodingOptions = { let decodingOptions = {
...@@ -171,9 +171,9 @@ imageSourceApi.createPixelMap(decodingOptions, pixelmap => { ...@@ -171,9 +171,9 @@ imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
// Create a pixel map in promise mode. // Create a pixel map in promise mode.
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();
}) })
// Capture error information when an exception occurs during function invoking. // Capture error information when an exception occurs during function invoking.
...@@ -181,7 +181,7 @@ catch(error => { ...@@ -181,7 +181,7 @@ catch(error => {
console.log('TC_050-11 error: ' + error); console.log('TC_050-11 error: ' + error);
expect().assertFail(); expect().assertFail();
done(); done();
}) })
// Obtain the number of bytes in each line of pixels. // Obtain the number of bytes in each line of pixels.
pixelmap.getBytesNumberPerRow( num => { pixelmap.getBytesNumberPerRow( num => {
...@@ -192,13 +192,13 @@ pixelmap.getBytesNumberPerRow( num => { ...@@ -192,13 +192,13 @@ pixelmap.getBytesNumberPerRow( num => {
// Obtain the total number of pixel bytes. // Obtain the total number of pixel bytes.
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();
}) })
// Obtain the pixel map information. // Obtain the pixel map information.
pixelmap.getImageInfo( imageInfo => {}) pixelmap.getImageInfo( imageInfo => {})
// Print the failure information. // Print the failure information.
console.info('TC_024-1 imageInfo is empty'); console.info('TC_024-1 imageInfo is empty');
...@@ -206,17 +206,17 @@ expect(false).assertTrue() ...@@ -206,17 +206,17 @@ expect(false).assertTrue()
// Release the PixelMap object. // Release the PixelMap object.
pixelmap.release(()=>{ pixelmap.release(()=>{
expect(true).assertTrue(); expect(true).assertTrue();
console.log('TC_027-1 suc'); console.log('TC_027-1 suc');
done(); done();
}) })
// Capture release failure information. // Capture release failure information.
catch(error => { catch(error => {
console.log('TC_027-1 error: ' + error); console.log('TC_027-1 error: ' + error);
expect().assertFail(); expect().assertFail();
done(); done();
}) })
``` ```
### Encoding Scenario ### Encoding Scenario
...@@ -225,14 +225,14 @@ catch(error => { ...@@ -225,14 +225,14 @@ catch(error => {
/data/local/tmp/test.png // Set the path for creating an image source. /data/local/tmp/test.png // Set the path for creating an image source.
// Set the image source. // Set the image source.
const imageSourceApi = image.createImageSource(path);//'/data/local/tmp/test.png' const imageSourceApi = image.createImageSource(path); // '/data/local/tmp/test.png'
// Print the error message if the image source fails to be created. // Print the error message if the image source fails to be created.
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();
} }
// Create an image packer if the image source is successfully created. // Create an image packer if the image source is successfully created.
const imagePackerApi = image.createImagePacker(); const imagePackerApi = image.createImagePacker();
...@@ -242,31 +242,58 @@ if (imagePackerApi == null) { ...@@ -242,31 +242,58 @@ 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();
} }
// Set encoding parameters if the image packer is successfully created. // Set encoding parameters if the image packer is successfully created.
let packOpts = { format:["image/jpeg"], // The supported encoding format is jpg. let packOpts = { format:["image/jpeg"], // The supported encoding format is jpg.
quality:98 }// Image quality, which ranges from 0 to 100. quality:98 } // Image quality, which ranges from 0 to 100.
// Encode the image. // Encode the image.
imagePackerApi.packing(imageSourceApi, packOpts) imagePackerApi.packing(imageSourceApi, packOpts)
.then( data => { .then( data => {
console.info('TC_062 finished'); console.info('TC_062 finished');
expect(data !== null).assertTrue(); expect(data !== null).assertTrue();
done(); done();
}) })
// Release the image packer after the encoding is complete. // Release the image packer after the encoding is complete.
imagePackerApi.release(); imagePackerApi.release();
// Obtain the image source information. // Obtain the image source information.
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();
}) })
// Update incremental data. // Update incremental data.
imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error,data )=> {}) imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error,data )=> {})
``` ```
### Using ImageReceiver
Example scenario: The camera functions as the client to transmit image data to the server.
```js
public async init(surfaceId: any) {
// (Server code) Create an ImageReceiver object.
var receiver = image.createImageReceiver(8 * 1024, 8, image.ImageFormat.JPEG, 1);
// Obtain the surface ID.
var surfaceId = await receiver.getReceivingSurfaceId();
// Register a surface listener, which is triggered after the buffer of the surface is ready.
receiver.on('imageArrival', () => {
// Obtain the latest buffer of the surface.
receiver.readNextImage((err, img) => {
img.getComponent(4, (err, component) => {
// Consume component.byteBuffer. For example, save the content in the buffer as an image.
})
})
})
// Call a Camera API to transfer the surface ID to the camera, which then obtains the surface based on the surface ID and generates a surface buffer.
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册