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