161847f8eSopenharmony_ci/*
261847f8eSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
461847f8eSopenharmony_ci * you may not use this file except in compliance with the License.
561847f8eSopenharmony_ci * You may obtain a copy of the License at
661847f8eSopenharmony_ci *
761847f8eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
861847f8eSopenharmony_ci *
961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and
1361847f8eSopenharmony_ci * limitations under the License.
1461847f8eSopenharmony_ci */
1561847f8eSopenharmony_ci
1661847f8eSopenharmony_ci/**
1761847f8eSopenharmony_ci * @file
1861847f8eSopenharmony_ci * @kit ArkUI
1961847f8eSopenharmony_ci */
2061847f8eSopenharmony_ci
2161847f8eSopenharmony_ciimport { AsyncCallback, ErrorCallback } from './@ohos.base';
2261847f8eSopenharmony_ciimport image from './@ohos.multimedia.image';
2361847f8eSopenharmony_ci
2461847f8eSopenharmony_ci /**
2561847f8eSopenharmony_ci * Declares the screenshot APIs.
2661847f8eSopenharmony_ci *
2761847f8eSopenharmony_ci * @namespace screenshot
2861847f8eSopenharmony_ci * @syscap SystemCapability.WindowManager.WindowManager.Core
2961847f8eSopenharmony_ci * @atomicservice
3061847f8eSopenharmony_ci * @since 12
3161847f8eSopenharmony_ci */
3261847f8eSopenharmony_cideclare namespace screenshot {
3361847f8eSopenharmony_ci  /**
3461847f8eSopenharmony_ci   * Takes a screenshot and saves it as a PixelMap object.
3561847f8eSopenharmony_ci   *
3661847f8eSopenharmony_ci   * @permission ohos.permission.CAPTURE_SCREEN
3761847f8eSopenharmony_ci   * @param { ScreenshotOptions } options Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters
3861847f8eSopenharmony_ci   * @param { AsyncCallback<image.PixelMap> } callback Callback used to return a PixelMap object.
3961847f8eSopenharmony_ci   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
4061847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified.
4161847f8eSopenharmony_ci   * <br>2.Incorrect parameter types.
4261847f8eSopenharmony_ci   * @syscap SystemCapability.WindowManager.WindowManager.Core
4361847f8eSopenharmony_ci   * @systemapi Hide this for inner system use.
4461847f8eSopenharmony_ci   * @since 7
4561847f8eSopenharmony_ci   */
4661847f8eSopenharmony_ci  /**
4761847f8eSopenharmony_ci   * Takes a screenshot and saves it as a PixelMap object.
4861847f8eSopenharmony_ci   *
4961847f8eSopenharmony_ci   * @permission ohos.permission.CAPTURE_SCREEN
5061847f8eSopenharmony_ci   * @param { ScreenshotOptions } options - Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters
5161847f8eSopenharmony_ci   * @param { AsyncCallback<image.PixelMap> } callback - Callback used to return a PixelMap object.
5261847f8eSopenharmony_ci   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
5361847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
5461847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified.
5561847f8eSopenharmony_ci   * <br>2.Incorrect parameter types.
5661847f8eSopenharmony_ci   * @throws { BusinessError } 1400001 - Invalid display or screen.
5761847f8eSopenharmony_ci   * @syscap SystemCapability.WindowManager.WindowManager.Core
5861847f8eSopenharmony_ci   * @systemapi Hide this for inner system use.
5961847f8eSopenharmony_ci   * @since 11
6061847f8eSopenharmony_ci   */
6161847f8eSopenharmony_ci  function save(options: ScreenshotOptions, callback: AsyncCallback<image.PixelMap>): void;
6261847f8eSopenharmony_ci
6361847f8eSopenharmony_ci  /**
6461847f8eSopenharmony_ci   * Takes a screenshot and saves it as a PixelMap object.
6561847f8eSopenharmony_ci   *
6661847f8eSopenharmony_ci   * @permission ohos.permission.CAPTURE_SCREEN
6761847f8eSopenharmony_ci   * @param { AsyncCallback<image.PixelMap> } callback Callback used to return a PixelMap object.
6861847f8eSopenharmony_ci   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
6961847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
7061847f8eSopenharmony_ci   * @syscap SystemCapability.WindowManager.WindowManager.Core
7161847f8eSopenharmony_ci   * @systemapi Hide this for inner system use.
7261847f8eSopenharmony_ci   * @since 7
7361847f8eSopenharmony_ci   */
7461847f8eSopenharmony_ci  function save(callback: AsyncCallback<image.PixelMap>): void;
7561847f8eSopenharmony_ci
7661847f8eSopenharmony_ci  /**
7761847f8eSopenharmony_ci   * Takes a screenshot and saves it as a PixelMap object.
7861847f8eSopenharmony_ci   *
7961847f8eSopenharmony_ci   * @permission ohos.permission.CAPTURE_SCREEN
8061847f8eSopenharmony_ci   * @param { ScreenshotOptions } options Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters
8161847f8eSopenharmony_ci   * @returns { Promise<image.PixelMap> } Promise used to return a PixelMap object.
8261847f8eSopenharmony_ci   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
8361847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
8461847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified.
8561847f8eSopenharmony_ci   * <br>2.Incorrect parameter types.
8661847f8eSopenharmony_ci   * @syscap SystemCapability.WindowManager.WindowManager.Core
8761847f8eSopenharmony_ci   * @systemapi Hide this for inner system use.
8861847f8eSopenharmony_ci   * @since 7
8961847f8eSopenharmony_ci   */
9061847f8eSopenharmony_ci  function save(options?: ScreenshotOptions): Promise<image.PixelMap>;
9161847f8eSopenharmony_ci
9261847f8eSopenharmony_ci  /**
9361847f8eSopenharmony_ci   * Takes a screenshot and picks it as a PickInfo object.
9461847f8eSopenharmony_ci   *
9561847f8eSopenharmony_ci   * @returns { Promise<PickInfo> } Promise used to return a PickInfo object.
9661847f8eSopenharmony_ci   * @throws { BusinessError } 801 - Capability not supported on this device.
9761847f8eSopenharmony_ci   * @throws { BusinessError } 1400003 - This display manager service works abnormally.
9861847f8eSopenharmony_ci   * @syscap SystemCapability.WindowManager.WindowManager.Core
9961847f8eSopenharmony_ci   * @atomicservice
10061847f8eSopenharmony_ci   * @since 12
10161847f8eSopenharmony_ci   */
10261847f8eSopenharmony_ci  function pick(): Promise<PickInfo>;
10361847f8eSopenharmony_ci
10461847f8eSopenharmony_ci  /**
10561847f8eSopenharmony_ci   * Describes the region of the screen to pick info.
10661847f8eSopenharmony_ci   *
10761847f8eSopenharmony_ci   * @interface PickInfo
10861847f8eSopenharmony_ci   * @syscap SystemCapability.WindowManager.WindowManager.Core
10961847f8eSopenharmony_ci   * @atomicservice
11061847f8eSopenharmony_ci   * @since 12
11161847f8eSopenharmony_ci   */
11261847f8eSopenharmony_ci  interface PickInfo {
11361847f8eSopenharmony_ci    /**
11461847f8eSopenharmony_ci     * the region of the screen to capture.
11561847f8eSopenharmony_ci     *
11661847f8eSopenharmony_ci     * @type { Rect }
11761847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
11861847f8eSopenharmony_ci     * @atomicservice
11961847f8eSopenharmony_ci     * @since 12
12061847f8eSopenharmony_ci     */
12161847f8eSopenharmony_ci    pickRect: Rect;
12261847f8eSopenharmony_ci
12361847f8eSopenharmony_ci    /**
12461847f8eSopenharmony_ci     * the region of the screen to capture pixelMap.
12561847f8eSopenharmony_ci     *
12661847f8eSopenharmony_ci     * @type { image.PixelMap }
12761847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
12861847f8eSopenharmony_ci     * @atomicservice
12961847f8eSopenharmony_ci     * @since 12
13061847f8eSopenharmony_ci     */
13161847f8eSopenharmony_ci    pixelMap: image.PixelMap;
13261847f8eSopenharmony_ci  }
13361847f8eSopenharmony_ci
13461847f8eSopenharmony_ci  /**
13561847f8eSopenharmony_ci   * Describes the region of the screen to capture.
13661847f8eSopenharmony_ci   *
13761847f8eSopenharmony_ci   * @interface Rect
13861847f8eSopenharmony_ci   * @syscap SystemCapability.WindowManager.WindowManager.Core
13961847f8eSopenharmony_ci   * @atomicservice
14061847f8eSopenharmony_ci   * @since 12
14161847f8eSopenharmony_ci   */
14261847f8eSopenharmony_ci  interface Rect {
14361847f8eSopenharmony_ci    /**
14461847f8eSopenharmony_ci     * The X-axis coordinate of the upper left vertex of the rectangle.
14561847f8eSopenharmony_ci     *
14661847f8eSopenharmony_ci     * @type { number }
14761847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
14861847f8eSopenharmony_ci     * @atomicservice
14961847f8eSopenharmony_ci     * @since 12
15061847f8eSopenharmony_ci     */
15161847f8eSopenharmony_ci    left: number;
15261847f8eSopenharmony_ci
15361847f8eSopenharmony_ci    /**
15461847f8eSopenharmony_ci     * The Y-axis coordinate of the upper left vertex of the rectangle.
15561847f8eSopenharmony_ci     *
15661847f8eSopenharmony_ci     * @type { number }
15761847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
15861847f8eSopenharmony_ci     * @atomicservice
15961847f8eSopenharmony_ci     * @since 12
16061847f8eSopenharmony_ci     */
16161847f8eSopenharmony_ci    top: number;
16261847f8eSopenharmony_ci
16361847f8eSopenharmony_ci    /**
16461847f8eSopenharmony_ci     * Width of the rectangle.
16561847f8eSopenharmony_ci     *
16661847f8eSopenharmony_ci     * @type { number }
16761847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
16861847f8eSopenharmony_ci     * @atomicservice
16961847f8eSopenharmony_ci     * @since 12
17061847f8eSopenharmony_ci     */
17161847f8eSopenharmony_ci    width: number;
17261847f8eSopenharmony_ci
17361847f8eSopenharmony_ci    /**
17461847f8eSopenharmony_ci     * Height of the rectangle.
17561847f8eSopenharmony_ci     *
17661847f8eSopenharmony_ci     * @type { number }
17761847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
17861847f8eSopenharmony_ci     * @atomicservice
17961847f8eSopenharmony_ci     * @since 12
18061847f8eSopenharmony_ci     */
18161847f8eSopenharmony_ci    height: number;
18261847f8eSopenharmony_ci  }
18361847f8eSopenharmony_ci
18461847f8eSopenharmony_ci  /**
18561847f8eSopenharmony_ci   * Describes the size of the screen region to capture.
18661847f8eSopenharmony_ci   *
18761847f8eSopenharmony_ci   * @interface Size
18861847f8eSopenharmony_ci   * @syscap SystemCapability.WindowManager.WindowManager.Core
18961847f8eSopenharmony_ci   * @systemapi Hide this for inner system use.
19061847f8eSopenharmony_ci   * @since 7
19161847f8eSopenharmony_ci   */
19261847f8eSopenharmony_ci  interface Size {
19361847f8eSopenharmony_ci    /**
19461847f8eSopenharmony_ci     * Defines the width property.
19561847f8eSopenharmony_ci     *
19661847f8eSopenharmony_ci     * @type { number }
19761847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
19861847f8eSopenharmony_ci     * @systemapi Hide this for inner system use.
19961847f8eSopenharmony_ci     * @since 7
20061847f8eSopenharmony_ci     */
20161847f8eSopenharmony_ci    width: number;
20261847f8eSopenharmony_ci
20361847f8eSopenharmony_ci    /**
20461847f8eSopenharmony_ci     * Defines the height property.
20561847f8eSopenharmony_ci     *
20661847f8eSopenharmony_ci     * @type { number }
20761847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
20861847f8eSopenharmony_ci     * @systemapi Hide this for inner system use.
20961847f8eSopenharmony_ci     * @since 7
21061847f8eSopenharmony_ci     */
21161847f8eSopenharmony_ci    height: number;
21261847f8eSopenharmony_ci  }
21361847f8eSopenharmony_ci
21461847f8eSopenharmony_ci  /**
21561847f8eSopenharmony_ci   * Describes screenshot options.
21661847f8eSopenharmony_ci   *
21761847f8eSopenharmony_ci   * @interface ScreenshotOptions
21861847f8eSopenharmony_ci   * @syscap SystemCapability.WindowManager.WindowManager.Core
21961847f8eSopenharmony_ci   * @systemapi Hide this for inner system use.
22061847f8eSopenharmony_ci   * @since 7
22161847f8eSopenharmony_ci   */
22261847f8eSopenharmony_ci  interface ScreenshotOptions {
22361847f8eSopenharmony_ci    /**
22461847f8eSopenharmony_ci     * Region of the screen to capture. If this parameter is null, the full screen will be captured.
22561847f8eSopenharmony_ci     *
22661847f8eSopenharmony_ci     * @type { ?Rect }
22761847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
22861847f8eSopenharmony_ci     * @systemapi Hide this for inner system use.
22961847f8eSopenharmony_ci     * @since 7
23061847f8eSopenharmony_ci     */
23161847f8eSopenharmony_ci    screenRect?: Rect;
23261847f8eSopenharmony_ci    /**
23361847f8eSopenharmony_ci     * Region of the screen to capture. If this parameter is null, the full screen will be captured.
23461847f8eSopenharmony_ci     *
23561847f8eSopenharmony_ci     * @type { ?Size }
23661847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
23761847f8eSopenharmony_ci     * @systemapi Hide this for inner system use.
23861847f8eSopenharmony_ci     * @since 7
23961847f8eSopenharmony_ci     */
24061847f8eSopenharmony_ci    imageSize?: Size;
24161847f8eSopenharmony_ci    /**
24261847f8eSopenharmony_ci     * Rotation angle of the screenshot. The value can be 0, 90, 180, or 270. The default value is 0.
24361847f8eSopenharmony_ci     *
24461847f8eSopenharmony_ci     * @type { ?number }
24561847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
24661847f8eSopenharmony_ci     * @systemapi Hide this for inner system use.
24761847f8eSopenharmony_ci     * @since 7
24861847f8eSopenharmony_ci     */
24961847f8eSopenharmony_ci    rotation?: number;
25061847f8eSopenharmony_ci    /**
25161847f8eSopenharmony_ci     * ID of the screen to be captured.
25261847f8eSopenharmony_ci     *
25361847f8eSopenharmony_ci     * @type { ?number }
25461847f8eSopenharmony_ci     * @syscap SystemCapability.WindowManager.WindowManager.Core
25561847f8eSopenharmony_ci     * @systemapi Hide this for inner system use.
25661847f8eSopenharmony_ci     * @since 8
25761847f8eSopenharmony_ci     */
25861847f8eSopenharmony_ci    displayId?: number;
25961847f8eSopenharmony_ci  }
26061847f8eSopenharmony_ci}
26161847f8eSopenharmony_ci
26261847f8eSopenharmony_ciexport default screenshot;
263