• 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
16/**
17 * @file
18 * @kit ArkUI
19 */
20
21import { AsyncCallback, ErrorCallback } from './@ohos.base';
22import image from './@ohos.multimedia.image';
23
24/**
25 * Declares the screenshot APIs.
26 *
27 * @namespace screenshot
28 * @syscap SystemCapability.WindowManager.WindowManager.Core
29 * @systemapi Hide this for inner system use.
30 * @since 7
31 */
32 /**
33 * Declares the screenshot APIs.
34 *
35 * @namespace screenshot
36 * @syscap SystemCapability.WindowManager.WindowManager.Core
37 * @since 12
38 */
39declare namespace screenshot {
40  /**
41   * Takes a screenshot and saves it as a PixelMap object.
42   *
43   * @permission ohos.permission.CAPTURE_SCREEN
44   * @param { ScreenshotOptions } options Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters
45   * @param { AsyncCallback<image.PixelMap> } callback Callback used to return a PixelMap object.
46   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
47   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified.
48   * <br>2.Incorrect parameter types.
49   * @syscap SystemCapability.WindowManager.WindowManager.Core
50   * @systemapi Hide this for inner system use.
51   * @since 7
52   */
53  /**
54   * Takes a screenshot and saves it as a PixelMap object.
55   *
56   * @permission ohos.permission.CAPTURE_SCREEN
57   * @param { ScreenshotOptions } options - Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters
58   * @param { AsyncCallback<image.PixelMap> } callback - Callback used to return a PixelMap object.
59   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
60   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
61   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified.
62   * <br>2.Incorrect parameter types.
63   * @throws { BusinessError } 1400001 - Invalid display or screen.
64   * @syscap SystemCapability.WindowManager.WindowManager.Core
65   * @systemapi Hide this for inner system use.
66   * @since 11
67   */
68  function save(options: ScreenshotOptions, callback: AsyncCallback<image.PixelMap>): void;
69
70  /**
71   * Takes a screenshot and saves it as a PixelMap object.
72   *
73   * @permission ohos.permission.CAPTURE_SCREEN
74   * @param { AsyncCallback<image.PixelMap> } callback Callback used to return a PixelMap object.
75   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
76   * @syscap SystemCapability.WindowManager.WindowManager.Core
77   * @systemapi Hide this for inner system use.
78   * @since 7
79   */
80  function save(callback: AsyncCallback<image.PixelMap>): void;
81
82  /**
83   * Takes a screenshot and saves it as a PixelMap object.
84   *
85   * @permission ohos.permission.CAPTURE_SCREEN
86   * @param { ScreenshotOptions } options Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters
87   * @returns { Promise<image.PixelMap> } Promise used to return a PixelMap object.
88   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
89   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified.
90   * <br>2.Incorrect parameter types.
91   * @syscap SystemCapability.WindowManager.WindowManager.Core
92   * @systemapi Hide this for inner system use.
93   * @since 7
94   */
95  function save(options?: ScreenshotOptions): Promise<image.PixelMap>;
96
97  /**
98   * Takes a screenshot and picks it as a PickInfo object.
99   *
100   * @returns { Promise<PickInfo> } Promise used to return a PickInfo object.
101   * @throws { BusinessError } 801 - Capability not supported on this device.
102   * @throws { BusinessError } 1400003 - This display manager service works abnormally.
103   * @syscap SystemCapability.WindowManager.WindowManager.Core
104   * @since 12
105   */
106  function pick(): Promise<PickInfo>;
107
108  /**
109   * Describes the region of the screen to pick info.
110   *
111   * @interface PickInfo
112   * @syscap SystemCapability.WindowManager.WindowManager.Core
113   * @since 12
114   */
115  interface PickInfo {
116    /**
117     * the region of the screen to capture.
118     *
119     * @type { Rect }
120     * @syscap SystemCapability.WindowManager.WindowManager.Core
121     * @since 12
122     */
123    pickRect: Rect;
124
125    /**
126     * the region of the screen to capture pixelMap.
127     *
128     * @type { image.PixelMap }
129     * @syscap SystemCapability.WindowManager.WindowManager.Core
130     * @since 12
131     */
132    pixelMap: image.PixelMap;
133  }
134
135  /**
136   * Describes the region of the screen to capture.
137   *
138   * @interface Rect
139   * @syscap SystemCapability.WindowManager.WindowManager.Core
140   * @systemapi Hide this for inner system use.
141   * @since 7
142   */
143  /**
144   * Describes the region of the screen to capture.
145   *
146   * @interface Rect
147   * @syscap SystemCapability.WindowManager.WindowManager.Core
148   * @since 12
149   */
150  interface Rect {
151    /**
152     * The X-axis coordinate of the upper left vertex of the rectangle.
153     *
154     * @type { number }
155     * @syscap SystemCapability.WindowManager.WindowManager.Core
156     * @systemapi Hide this for inner system use.
157     * @since 7
158     */
159    /**
160     * The X-axis coordinate of the upper left vertex of the rectangle.
161     *
162     * @type { number }
163     * @syscap SystemCapability.WindowManager.WindowManager.Core
164     * @since 12
165     */
166    left: number;
167
168    /**
169     * The Y-axis coordinate of the upper left vertex of the rectangle.
170     *
171     * @type { number }
172     * @syscap SystemCapability.WindowManager.WindowManager.Core
173     * @systemapi Hide this for inner system use.
174     * @since 7
175     */
176    /**
177     * The Y-axis coordinate of the upper left vertex of the rectangle.
178     *
179     * @type { number }
180     * @syscap SystemCapability.WindowManager.WindowManager.Core
181     * @since 12
182     */
183    top: number;
184
185    /**
186     * Width of the rectangle.
187     *
188     * @type { number }
189     * @syscap SystemCapability.WindowManager.WindowManager.Core
190     * @systemapi Hide this for inner system use.
191     * @since 7
192     */
193    /**
194     * Width of the rectangle.
195     *
196     * @type { number }
197     * @syscap SystemCapability.WindowManager.WindowManager.Core
198     * @since 12
199     */
200    width: number;
201
202    /**
203     * Height of the rectangle.
204     *
205     * @type { number }
206     * @syscap SystemCapability.WindowManager.WindowManager.Core
207     * @systemapi Hide this for inner system use.
208     * @since 7
209     */
210    /**
211     * Height of the rectangle.
212     *
213     * @type { number }
214     * @syscap SystemCapability.WindowManager.WindowManager.Core
215     * @since 12
216     */
217    height: number;
218  }
219
220  /**
221   * Describes the size of the screen region to capture.
222   *
223   * @interface Size
224   * @syscap SystemCapability.WindowManager.WindowManager.Core
225   * @systemapi Hide this for inner system use.
226   * @since 7
227   */
228  interface Size {
229    /**
230     * Defines the width property.
231     *
232     * @type { number }
233     * @syscap SystemCapability.WindowManager.WindowManager.Core
234     * @systemapi Hide this for inner system use.
235     * @since 7
236     */
237    width: number;
238
239    /**
240     * Defines the height property.
241     *
242     * @type { number }
243     * @syscap SystemCapability.WindowManager.WindowManager.Core
244     * @systemapi Hide this for inner system use.
245     * @since 7
246     */
247    height: number;
248  }
249
250  /**
251   * Describes screenshot options.
252   *
253   * @interface ScreenshotOptions
254   * @syscap SystemCapability.WindowManager.WindowManager.Core
255   * @systemapi Hide this for inner system use.
256   * @since 7
257   */
258  interface ScreenshotOptions {
259    /**
260     * Region of the screen to capture. If this parameter is null, the full screen will be captured.
261     *
262     * @syscap SystemCapability.WindowManager.WindowManager.Core
263     * @systemapi Hide this for inner system use.
264     * @since 7
265     */
266    screenRect?: Rect;
267    /**
268     * Region of the screen to capture. If this parameter is null, the full screen will be captured.
269     *
270     * @syscap SystemCapability.WindowManager.WindowManager.Core
271     * @systemapi Hide this for inner system use.
272     * @since 7
273     */
274    imageSize?: Size;
275    /**
276     * Rotation angle of the screenshot. The value can be 0, 90, 180, or 270. The default value is 0.
277     *
278     * @syscap SystemCapability.WindowManager.WindowManager.Core
279     * @systemapi Hide this for inner system use.
280     * @since 7
281     */
282    rotation?: number;
283    /**
284     * ID of the screen to be captured.
285     *
286     * @syscap SystemCapability.WindowManager.WindowManager.Core
287     * @systemapi Hide this for inner system use.
288     * @since 8
289     */
290    displayId?: number;
291  }
292}
293
294export default screenshot;
295