• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { AsyncCallback, ErrorCallback } from './basic';
17import image from './@ohos.multimedia.image';
18
19/**
20 * Declares the screenshot APIs.
21 * @syscap SystemCapability.WindowManager.WindowManager.Core
22 * @systemapi Hide this for inner system use.
23 * @since 7
24 */
25declare namespace screenshot {
26    /**
27     * Takes a screenshot and saves it as a PixelMap object.
28     * @param options Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters
29     * @permission ohos.permission.CAPTURE_SCREEN
30     * @throws {BusinessError} 201 - Permission verification failed.
31     * @throws {BusinessError} 401 - Parameter error.
32     * @since 7
33     */
34    function save(options: ScreenshotOptions, callback: AsyncCallback<image.PixelMap>): void;
35
36    /**
37     * Takes a screenshot and saves it as a PixelMap object.
38     * @param options Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters
39     * @permission ohos.permission.CAPTURE_SCREEN
40     * @throws {BusinessError} 201 - Permission verification failed.
41     * @since 7
42     */
43    function save(callback: AsyncCallback<image.PixelMap>): void;
44
45    /**
46     * Takes a screenshot and saves it as a PixelMap object.
47     * @param options Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters
48     * @permission ohos.permission.CAPTURE_SCREEN
49     * @throws {BusinessError} 201 - Permission verification failed.
50     * @throws {BusinessError} 401 - Parameter error.
51     * @since 7
52     */
53    function save(options?: ScreenshotOptions): Promise<image.PixelMap>;
54
55    /**
56     * Describes the region of the screen to capture.
57     * @since 7
58     */
59    interface Rect {
60        left: number;
61        top: number;
62        width: number;
63        height: number;
64    }
65
66    /**
67     * Describes the size of the screen region to capture.
68     * @since 7
69     */
70    interface Size {
71        width: number;
72        height: number;
73    }
74
75    /**
76     * Describes screenshot options.
77     * @since 7
78     */
79    interface ScreenshotOptions {
80        /**
81         * Region of the screen to capture. If this parameter is null, the full screen will be captured.
82         */
83        screenRect?: Rect;
84        /**
85         * Region of the screen to capture. If this parameter is null, the full screen will be captured.
86         */
87        imageSize?: Size;
88        /**
89         * Rotation angle of the screenshot. The value can be 0, 90, 180, or 270. The default value is 0.
90         */
91        rotation?: number;
92        /**
93         * ID of the screen to be captured.
94         * @since 8
95         */
96        displayId?: number;
97    }
98}
99
100export default screenshot;
101