From a809d4643c8d157ef13d52c1c0955a7fe720dbfc Mon Sep 17 00:00:00 2001 From: realice Date: Thu, 28 Jul 2022 11:22:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=96=99=EF=BC=9A=E6=88=AA=E5=B1=8F?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E3=80=81=E7=AA=97=E5=8F=A3=E6=88=AA=E5=9B=BE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: realice Change-Id: Iaf510e30c51429647fdf86d62afd90bea7874e82 --- .../reference/apis/js-apis-screenshot.md | 50 +++++---- .../reference/apis/js-apis-window.md | 104 ++++++++++++++++++ 2 files changed, 130 insertions(+), 24 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-screenshot.md b/zh-cn/application-dev/reference/apis/js-apis-screenshot.md index 6871f0ce05..c0126a92a3 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-screenshot.md +++ b/zh-cn/application-dev/reference/apis/js-apis-screenshot.md @@ -68,29 +68,30 @@ save(options?: ScreenshotOptions, callback: AsyncCallback<image.PixelMap>) | 参数名 | 类型 | 必填 | 说明 | | -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | options | [ScreenshotOptions](#screenshotoptions) | 否 | 该类型的参数包含screenRect,imageSize,rotation, displayId四个参数,可以分别设置这四个参数。 | -| callback | AsyncCallback<image.PixelMap> | 是 | 回调函数。返回一个PixelMap对象。 | +| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | 是 | 回调函数。返回一个PixelMap对象。 | **示例:** ```js - var ScreenshotOptions = { - "screenRect": { - "left": 200, - "top": 100, - "width": 200, - "height": 200}, - "imageSize": { - "width": 300, - "height": 300}, - "rotation": 0, - "displayId": 0 + var screenshotOptions = { + "screenRect": { + "left": 200, + "top": 100, + "width": 200, + "height": 200}, + "imageSize": { + "width": 300, + "height": 300}, + "rotation": 0, + "displayId": 0 }; - screenshot.save(ScreenshotOptions, (err, data) => { - if (err) { - console.error('Failed to save the screenshot. Error: ' + JSON.stringify(err)); - return; - } - console.info('Screenshot saved. Data: ' + JSON.stringify(data)); + screenshot.save(screenshotOptions, (err, pixelMap) => { + if (err) { + console.log('Failed to save screenshot: ' + JSON.stringify(err)); + return; + } + console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); + pixelMap.release(); // PixelMap使用完后及时释放内存 }); ``` @@ -114,12 +115,12 @@ save(options?: ScreenshotOptions): Promise<image.PixelMap> | 类型 | 说明 | | ----------------------------- | ----------------------------------------------- | -| Promise<image.PixelMap> | Promise对象。返回一个PixelMap对象。 | +| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise对象。返回一个PixelMap对象。 | **示例:** ```js - var ScreenshotOptions = { + var screenshotOptions = { "screenRect": { "left": 200, "top": 100, @@ -131,10 +132,11 @@ save(options?: ScreenshotOptions): Promise<image.PixelMap> "rotation": 0, "displayId": 0 }; - let promise = screenshot.save(ScreenshotOptions); - promise.then(() => { - console.log('screenshot save success'); + let promise = screenshot.save(screenshotOptions); + promise.then((pixelMap) => { + console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); + pixelMap.release(); // PixelMap使用完后及时释放内存 }).catch((err) => { - console.log('screenshot save fail: ' + JSON.stringify(err)); + console.log('Failed to save screenshot: ' + JSON.stringify(err)); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-window.md b/zh-cn/application-dev/reference/apis/js-apis-window.md index a4e79f184e..cae0c7d608 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-window.md +++ b/zh-cn/application-dev/reference/apis/js-apis-window.md @@ -1970,6 +1970,57 @@ off(type: 'touchOutside', callback?: Callback<void>): void windowClass.off('touchOutside'); ``` +### on('screenshot')9+ + +on(type: 'screenshot', callback: Callback<void>): void + +开启截屏事件的监听。 + +**系统能力:** SystemCapability.WindowManager.WindowManager.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件。 | +| callback | Callback<void> | 是 | 回调函数。发生截屏事件时的回调。 | + +**示例:** + +```js +windowClass.on('screenshot', () => { + console.info('screenshot happened'); +}); +``` + +### off('screenshot')9+ + +off(type: 'screenshot', callback?: Callback<void>): void + +关闭截屏事件的监听。 + +**系统能力:** SystemCapability.WindowManager.WindowManager.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---------------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件。 | +| callback | Callback<void> | 否 | 回调函数。发生截屏事件时的回调。 | + +**示例:** + +```js +var callback = ()=>{ + console.info('screenshot happened'); +} +windowClass.on('screenshot', callback) +windowClass.off('screenshot', callback) + +// 如果通过on开启多个callback进行监听,同时关闭所有监听: +windowClass.off('screenshot'); +``` + ### isSupportWideGamut8+ isSupportWideGamut(callback: AsyncCallback<boolean>): void @@ -2689,6 +2740,59 @@ promise.then((data)=> { }); ``` +### snapshot9+ + +snapshot(callback: AsyncCallback<image.PixelMap>): void + +获取窗口截图,使用callback异步回调。 + +**系统能力:** SystemCapability.WindowManager.WindowManager.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ----------- | ------------------------- | ---- | -------------------- | +| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | 是 | 回调函数。 | + +**示例:** + +```js +windowClass.snapshot((err, data) => { + if (err.code) { + console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); + data.release(); // PixelMap使用完后及时释放内存 +}); +``` + +### snapshot9+ + +snapshot(): Promise<image.PixelMap> + +获取窗口截图,使用Promise异步回调。 + +**系统能力:** SystemCapability.WindowManager.WindowManager.Core + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ------------------------- | +| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise对象。返回当前窗口截图。 | + +**示例:** + +```js +let promise = windowClass.snapshot(); +promise.then((pixelMap)=> { + console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); + pixelMap.release(); // PixelMap使用完后及时释放内存 +}).catch((err)=>{ + console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); +}); +``` + ## WindowStageEventType9+ WindowStage生命周期。 -- GitLab