You need to sign in or sign up before continuing.
screenshot-guidelines.md 1.1 KB
Newer Older
W
wusongqing 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
# Screenshot Development

## When to Use

You can specify a display device to take screenshots, with screenshot parameters specified.

## Available APIs

For details about the APIs, see [Screenshot](../reference/apis/js-apis-screenshot.md).

## How to Develop

Call **save(options?: ScreenshotOptions): Promise<image.PixelMap>** to take a screenshot. In this API, **options** is a predefined screenshot parameter. If **options** is unspecified, the entire screen is captured by default. An example code snippet is as follows:

```js
import screenshot from '@ohos.screenshot' // Import the module.

// Set screenshot parameters.
var ScreenshotOptions = {
	"screenRect": {
		"left": 200,
		"top": 100,
		"width": 200,
		"height": 200},
	"imageSize": {
		"width": 300,
		"height": 300},
	"rotation": 0
};

let image; // image is used to save the screenshot.
screenshot.save(ScreenshotOptions).then((image) => {
	console.log('screenshot.save success, screenshot image :' + JSON.stringify(image));
}, (err) => {
    console.log('screenshot.save failed, error : ' + JSON.stringify(err));
})
```