未验证 提交 9219e16e 编写于 作者: O openharmony_ci 提交者: Gitee

!6666 资料:截屏监听、窗口截图接口

Merge pull request !6666 from 韩冰/snapshot
......@@ -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));
});
```
......@@ -1970,6 +1970,57 @@ off(type: 'touchOutside', callback?: Callback<void>): void
windowClass.off('touchOutside');
```
### on('screenshot')<sup>9+</sup>
on(type: 'screenshot', callback: Callback&lt;void&gt;): void
开启截屏事件的监听。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件。 |
| callback | Callback&lt;void&gt; | 是 | 回调函数。发生截屏事件时的回调。 |
**示例:**
```js
windowClass.on('screenshot', () => {
console.info('screenshot happened');
});
```
### off('screenshot')<sup>9+</sup>
off(type: 'screenshot', callback?: Callback&lt;void&gt;): void
关闭截屏事件的监听。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件。 |
| callback | Callback&lt;void&gt; | 否 | 回调函数。发生截屏事件时的回调。 |
**示例:**
```js
var callback = ()=>{
console.info('screenshot happened');
}
windowClass.on('screenshot', callback)
windowClass.off('screenshot', callback)
// 如果通过on开启多个callback进行监听,同时关闭所有监听:
windowClass.off('screenshot');
```
### isSupportWideGamut<sup>8+</sup>
isSupportWideGamut(callback: AsyncCallback&lt;boolean&gt;): void
......@@ -2689,6 +2740,59 @@ promise.then((data)=> {
});
```
### snapshot<sup>9+</sup>
snapshot(callback: AsyncCallback&lt;image.PixelMap&gt;): void
获取窗口截图,使用callback异步回调。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------------------------- | ---- | -------------------- |
| callback | AsyncCallback&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | 是 | 回调函数。 |
**示例:**
```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使用完后及时释放内存
});
```
### snapshot<sup>9+</sup>
snapshot(): Promise&lt;image.PixelMap&gt;
获取窗口截图,使用Promise异步回调。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | 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));
});
```
## WindowStageEventType<sup>9+</sup>
WindowStage生命周期。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册