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 screenshot and picks it as a PickInfo object. 94 * 95 * @returns { Promise<PickInfo> } Promise used to return a PickInfo object. 96 * @throws { BusinessError } 801 - Capability not supported on this device. 97 * @throws { BusinessError } 1400003 - This display manager service works abnormally. 98 * @syscap SystemCapability.WindowManager.WindowManager.Core 99 * @atomicservice 100 * @since 12 101 */ 102 function pick(): Promise<PickInfo>; 103 104 /** 105 * Describes the region of the screen to pick info. 106 * 107 * @interface PickInfo 108 * @syscap SystemCapability.WindowManager.WindowManager.Core 109 * @atomicservice 110 * @since 12 111 */ 112 interface PickInfo { 113 /** 114 * the region of the screen to capture. 115 * 116 * @type { Rect } 117 * @syscap SystemCapability.WindowManager.WindowManager.Core 118 * @atomicservice 119 * @since 12 120 */ 121 pickRect: Rect; 122 123 /** 124 * the region of the screen to capture pixelMap. 125 * 126 * @type { image.PixelMap } 127 * @syscap SystemCapability.WindowManager.WindowManager.Core 128 * @atomicservice 129 * @since 12 130 */ 131 pixelMap: image.PixelMap; 132 } 133 134 /** 135 * Describes the region of the screen to capture. 136 * 137 * @interface Rect 138 * @syscap SystemCapability.WindowManager.WindowManager.Core 139 * @atomicservice 140 * @since 12 141 */ 142 interface Rect { 143 /** 144 * The X-axis coordinate of the upper left vertex of the rectangle. 145 * 146 * @type { number } 147 * @syscap SystemCapability.WindowManager.WindowManager.Core 148 * @atomicservice 149 * @since 12 150 */ 151 left: number; 152 153 /** 154 * The Y-axis coordinate of the upper left vertex of the rectangle. 155 * 156 * @type { number } 157 * @syscap SystemCapability.WindowManager.WindowManager.Core 158 * @atomicservice 159 * @since 12 160 */ 161 top: number; 162 163 /** 164 * Width of the rectangle. 165 * 166 * @type { number } 167 * @syscap SystemCapability.WindowManager.WindowManager.Core 168 * @atomicservice 169 * @since 12 170 */ 171 width: number; 172 173 /** 174 * Height of the rectangle. 175 * 176 * @type { number } 177 * @syscap SystemCapability.WindowManager.WindowManager.Core 178 * @atomicservice 179 * @since 12 180 */ 181 height: number; 182 } 183 184 /** 185 * Describes the size of the screen region to capture. 186 * 187 * @interface Size 188 * @syscap SystemCapability.WindowManager.WindowManager.Core 189 * @systemapi Hide this for inner system use. 190 * @since 7 191 */ 192 interface Size { 193 /** 194 * Defines the width property. 195 * 196 * @type { number } 197 * @syscap SystemCapability.WindowManager.WindowManager.Core 198 * @systemapi Hide this for inner system use. 199 * @since 7 200 */ 201 width: number; 202 203 /** 204 * Defines the height property. 205 * 206 * @type { number } 207 * @syscap SystemCapability.WindowManager.WindowManager.Core 208 * @systemapi Hide this for inner system use. 209 * @since 7 210 */ 211 height: number; 212 } 213 214 /** 215 * Describes screenshot options. 216 * 217 * @interface ScreenshotOptions 218 * @syscap SystemCapability.WindowManager.WindowManager.Core 219 * @systemapi Hide this for inner system use. 220 * @since 7 221 */ 222 interface ScreenshotOptions { 223 /** 224 * Region of the screen to capture. If this parameter is null, the full screen will be captured. 225 * 226 * @type { ?Rect } 227 * @syscap SystemCapability.WindowManager.WindowManager.Core 228 * @systemapi Hide this for inner system use. 229 * @since 7 230 */ 231 screenRect?: Rect; 232 /** 233 * Region of the screen to capture. If this parameter is null, the full screen will be captured. 234 * 235 * @type { ?Size } 236 * @syscap SystemCapability.WindowManager.WindowManager.Core 237 * @systemapi Hide this for inner system use. 238 * @since 7 239 */ 240 imageSize?: Size; 241 /** 242 * Rotation angle of the screenshot. The value can be 0, 90, 180, or 270. The default value is 0. 243 * 244 * @type { ?number } 245 * @syscap SystemCapability.WindowManager.WindowManager.Core 246 * @systemapi Hide this for inner system use. 247 * @since 7 248 */ 249 rotation?: number; 250 /** 251 * ID of the screen to be captured. 252 * 253 * @type { ?number } 254 * @syscap SystemCapability.WindowManager.WindowManager.Core 255 * @systemapi Hide this for inner system use. 256 * @since 8 257 */ 258 displayId?: number; 259 } 260} 261 262export default screenshot; 263