161847f8eSopenharmony_ci/* 261847f8eSopenharmony_ci * Copyright (c) 2023 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 } from './@ohos.base'; 2261847f8eSopenharmony_ciimport image from './@ohos.multimedia.image' 2361847f8eSopenharmony_ci 2461847f8eSopenharmony_ci/** 2561847f8eSopenharmony_ci * This module allows developers to export snapshot image from a component or a custom builder. 2661847f8eSopenharmony_ci * 2761847f8eSopenharmony_ci * @namespace componentSnapshot 2861847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 2961847f8eSopenharmony_ci * @crossplatform 3061847f8eSopenharmony_ci * @since 10 3161847f8eSopenharmony_ci */ 3261847f8eSopenharmony_ci/** 3361847f8eSopenharmony_ci * This module allows developers to export snapshot image from a component or a custom builder. 3461847f8eSopenharmony_ci * 3561847f8eSopenharmony_ci * @namespace componentSnapshot 3661847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 3761847f8eSopenharmony_ci * @crossplatform 3861847f8eSopenharmony_ci * @atomicservice 3961847f8eSopenharmony_ci * @since 12 4061847f8eSopenharmony_ci */ 4161847f8eSopenharmony_cideclare namespace componentSnapshot { 4261847f8eSopenharmony_ci /** 4361847f8eSopenharmony_ci * Defines the extra options for snapshot taking. 4461847f8eSopenharmony_ci * 4561847f8eSopenharmony_ci * @typedef SnapshotOptions 4661847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 4761847f8eSopenharmony_ci * @crossplatform 4861847f8eSopenharmony_ci * @atomicservice 4961847f8eSopenharmony_ci * @since 12 5061847f8eSopenharmony_ci */ 5161847f8eSopenharmony_ci interface SnapshotOptions { 5261847f8eSopenharmony_ci /** 5361847f8eSopenharmony_ci * Defines the scale property to render the snapshot. 5461847f8eSopenharmony_ci * 5561847f8eSopenharmony_ci * @type {?number} 5661847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 5761847f8eSopenharmony_ci * @crossplatform 5861847f8eSopenharmony_ci * @atomicservice 5961847f8eSopenharmony_ci * @since 12 6061847f8eSopenharmony_ci */ 6161847f8eSopenharmony_ci scale?: number 6261847f8eSopenharmony_ci 6361847f8eSopenharmony_ci /** 6461847f8eSopenharmony_ci * Whether to wait the rendering is finished. 6561847f8eSopenharmony_ci * 6661847f8eSopenharmony_ci * @type {?boolean} 6761847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 6861847f8eSopenharmony_ci * @crossplatform 6961847f8eSopenharmony_ci * @atomicservice 7061847f8eSopenharmony_ci * @since 12 7161847f8eSopenharmony_ci */ 7261847f8eSopenharmony_ci waitUntilRenderFinished?: boolean 7361847f8eSopenharmony_ci } 7461847f8eSopenharmony_ci 7561847f8eSopenharmony_ci /** 7661847f8eSopenharmony_ci * Take a snapshot of the target component. 7761847f8eSopenharmony_ci * 7861847f8eSopenharmony_ci * @param { string } id - Target component ID, set by developer through .id attribute. 7961847f8eSopenharmony_ci * @param { AsyncCallback<image.PixelMap> } callback - Callback that contains the snapshot in PixelMap format. 8061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 8161847f8eSopenharmony_ci * <br> 1. Mandatory parameters are left unspecified. 8261847f8eSopenharmony_ci * <br> 2. Incorrect parameters types. 8361847f8eSopenharmony_ci * <br> 3. Parameter verification failed. 8461847f8eSopenharmony_ci * @throws { BusinessError } 100001 - Invalid ID. 8561847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 8661847f8eSopenharmony_ci * @crossplatform 8761847f8eSopenharmony_ci * @since 10 8861847f8eSopenharmony_ci */ 8961847f8eSopenharmony_ci /** 9061847f8eSopenharmony_ci * Take a snapshot of the target component. 9161847f8eSopenharmony_ci * 9261847f8eSopenharmony_ci * @param { string } id - Target component ID, set by developer through .id attribute. 9361847f8eSopenharmony_ci * @param { AsyncCallback<image.PixelMap> } callback - Callback that contains the snapshot in PixelMap format. 9461847f8eSopenharmony_ci * @param { SnapshotOptions } [options] - Define the snapshot options. 9561847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 9661847f8eSopenharmony_ci * <br> 1. Mandatory parameters are left unspecified. 9761847f8eSopenharmony_ci * <br> 2. Incorrect parameters types. 9861847f8eSopenharmony_ci * <br> 3. Parameter verification failed. 9961847f8eSopenharmony_ci * @throws { BusinessError } 100001 - Invalid ID. 10061847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 10161847f8eSopenharmony_ci * @crossplatform 10261847f8eSopenharmony_ci * @atomicservice 10361847f8eSopenharmony_ci * @since 12 10461847f8eSopenharmony_ci */ 10561847f8eSopenharmony_ci function get(id: string, callback: AsyncCallback<image.PixelMap>, options?: SnapshotOptions): void; 10661847f8eSopenharmony_ci 10761847f8eSopenharmony_ci /** 10861847f8eSopenharmony_ci * Take a snapshot of the target component. 10961847f8eSopenharmony_ci * 11061847f8eSopenharmony_ci * @param { string } id - Target component ID, set by developer through .id attribute. 11161847f8eSopenharmony_ci * @returns { Promise<image.PixelMap> } A Promise with the snapshot in PixelMap format. 11261847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 11361847f8eSopenharmony_ci * <br> 1. Mandatory parameters are left unspecified. 11461847f8eSopenharmony_ci * <br> 2. Incorrect parameters types. 11561847f8eSopenharmony_ci * <br> 3. Parameter verification failed. 11661847f8eSopenharmony_ci * @throws { BusinessError } 100001 - Invalid ID. 11761847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 11861847f8eSopenharmony_ci * @crossplatform 11961847f8eSopenharmony_ci * @since 10 12061847f8eSopenharmony_ci */ 12161847f8eSopenharmony_ci /** 12261847f8eSopenharmony_ci * Take a snapshot of the target component. 12361847f8eSopenharmony_ci * 12461847f8eSopenharmony_ci * @param { string } id - Target component ID, set by developer through .id attribute. 12561847f8eSopenharmony_ci * @param { SnapshotOptions } [options] - Define the snapshot options. 12661847f8eSopenharmony_ci * @returns { Promise<image.PixelMap> } A Promise with the snapshot in PixelMap format. 12761847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 12861847f8eSopenharmony_ci * <br> 1. Mandatory parameters are left unspecified. 12961847f8eSopenharmony_ci * <br> 2. Incorrect parameters types. 13061847f8eSopenharmony_ci * <br> 3. Parameter verification failed. 13161847f8eSopenharmony_ci * @throws { BusinessError } 100001 - Invalid ID. 13261847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 13361847f8eSopenharmony_ci * @crossplatform 13461847f8eSopenharmony_ci * @atomicservice 13561847f8eSopenharmony_ci * @since 12 13661847f8eSopenharmony_ci */ 13761847f8eSopenharmony_ci function get(id: string, options?: SnapshotOptions): Promise<image.PixelMap>; 13861847f8eSopenharmony_ci 13961847f8eSopenharmony_ci /** 14061847f8eSopenharmony_ci * Generate a snapshot from a custom component builder. 14161847f8eSopenharmony_ci * 14261847f8eSopenharmony_ci * @param { CustomBuilder } builder - Builder function of a custom component. 14361847f8eSopenharmony_ci * @param { AsyncCallback<image.PixelMap> } callback - Callback that contains the snapshot in PixelMap format. 14461847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 14561847f8eSopenharmony_ci * <br> 1. Mandatory parameters are left unspecified. 14661847f8eSopenharmony_ci * <br> 2. Incorrect parameters types. 14761847f8eSopenharmony_ci * <br> 3. Parameter verification failed. 14861847f8eSopenharmony_ci * @throws { BusinessError } 100001 - The builder is not a valid build function. 14961847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 15061847f8eSopenharmony_ci * @crossplatform 15161847f8eSopenharmony_ci * @since 10 15261847f8eSopenharmony_ci */ 15361847f8eSopenharmony_ci /** 15461847f8eSopenharmony_ci * Generate a snapshot from a custom component builder. 15561847f8eSopenharmony_ci * 15661847f8eSopenharmony_ci * @param { CustomBuilder } builder - Builder function of a custom component. 15761847f8eSopenharmony_ci * @param { AsyncCallback<image.PixelMap> } callback - Callback that contains the snapshot in PixelMap format. 15861847f8eSopenharmony_ci * @param { number } [delay] - Defines the delay time to render the snapshot. 15961847f8eSopenharmony_ci * @param { boolean } [checkImageStatus] - Defines if check the image decoding status before taking snapshot. 16061847f8eSopenharmony_ci * @param { SnapshotOptions } [options] - Define the snapshot options. 16161847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 16261847f8eSopenharmony_ci * <br> 1. Mandatory parameters are left unspecified. 16361847f8eSopenharmony_ci * <br> 2. Incorrect parameters types. 16461847f8eSopenharmony_ci * <br> 3. Parameter verification failed. 16561847f8eSopenharmony_ci * @throws { BusinessError } 100001 - The builder is not a valid build function. 16661847f8eSopenharmony_ci * @throws { BusinessError } 160001 - An image component in builder is not ready for taking a snapshot. The check for 16761847f8eSopenharmony_ci * the ready state is required when the checkImageStatus option is enabled. 16861847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 16961847f8eSopenharmony_ci * @crossplatform 17061847f8eSopenharmony_ci * @atomicservice 17161847f8eSopenharmony_ci * @since 12 17261847f8eSopenharmony_ci */ 17361847f8eSopenharmony_ci function createFromBuilder(builder: CustomBuilder, callback: AsyncCallback<image.PixelMap>, 17461847f8eSopenharmony_ci delay?: number, checkImageStatus?: boolean, options?: SnapshotOptions): void; 17561847f8eSopenharmony_ci 17661847f8eSopenharmony_ci /** 17761847f8eSopenharmony_ci * Generate a snapshot from a custom component builder. 17861847f8eSopenharmony_ci * 17961847f8eSopenharmony_ci * @param { CustomBuilder } builder - Builder function of a custom component. 18061847f8eSopenharmony_ci * @returns { Promise<image.PixelMap> } A Promise with the snapshot in PixelMap format. 18161847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 18261847f8eSopenharmony_ci * <br> 1. Mandatory parameters are left unspecified. 18361847f8eSopenharmony_ci * <br> 2. Incorrect parameters types. 18461847f8eSopenharmony_ci * <br> 3. Parameter verification failed. 18561847f8eSopenharmony_ci * @throws { BusinessError } 100001 - The builder is not a valid build function. 18661847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 18761847f8eSopenharmony_ci * @crossplatform 18861847f8eSopenharmony_ci * @since 10 18961847f8eSopenharmony_ci */ 19061847f8eSopenharmony_ci /** 19161847f8eSopenharmony_ci * Generate a snapshot from a custom component builder. 19261847f8eSopenharmony_ci * 19361847f8eSopenharmony_ci * @param { CustomBuilder } builder - Builder function of a custom component. 19461847f8eSopenharmony_ci * @param { number } [delay] - Defines the delay time to render the snapshot. 19561847f8eSopenharmony_ci * @param { boolean } [checkImageStatus] - Defines if check the image decoding status before taking snapshot. 19661847f8eSopenharmony_ci * @param { SnapshotOptions } [options] - Define the snapshot options. 19761847f8eSopenharmony_ci * @returns { Promise<image.PixelMap> } A Promise with the snapshot in PixelMap format. 19861847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 19961847f8eSopenharmony_ci * <br> 1. Mandatory parameters are left unspecified. 20061847f8eSopenharmony_ci * <br> 2. Incorrect parameters types. 20161847f8eSopenharmony_ci * <br> 3. Parameter verification failed. 20261847f8eSopenharmony_ci * @throws { BusinessError } 100001 - The builder is not a valid build function. 20361847f8eSopenharmony_ci * @throws { BusinessError } 160001 - An image component in builder is not ready for taking a snapshot. The check for 20461847f8eSopenharmony_ci * the ready state is required when the checkImageStatus option is enabled. 20561847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 20661847f8eSopenharmony_ci * @crossplatform 20761847f8eSopenharmony_ci * @atomicservice 20861847f8eSopenharmony_ci * @since 12 20961847f8eSopenharmony_ci */ 21061847f8eSopenharmony_ci function createFromBuilder(builder: CustomBuilder, delay?: number, 21161847f8eSopenharmony_ci checkImageStatus?: boolean, options?: SnapshotOptions): Promise<image.PixelMap>; 21261847f8eSopenharmony_ci 21361847f8eSopenharmony_ci /** 21461847f8eSopenharmony_ci * Take a screenshot of the specified component in synchronous mode, 21561847f8eSopenharmony_ci * this mode will block the main thread, please use it with caution, the maximum 21661847f8eSopenharmony_ci * waiting time of the interface is 3s, if it does not return after 3s, an exception will be thrown. 21761847f8eSopenharmony_ci * 21861847f8eSopenharmony_ci * @param { string } id - Target component ID, set by developer through .id attribute. 21961847f8eSopenharmony_ci * @param { SnapshotOptions } [options] - Define the snapshot options. 22061847f8eSopenharmony_ci * @returns { image.PixelMap } The snapshot result in PixelMap format. 22161847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 22261847f8eSopenharmony_ci * <br> 1. Mandatory parameters are left unspecified. 22361847f8eSopenharmony_ci * <br> 2. Incorrect parameters types. 22461847f8eSopenharmony_ci * <br> 3. Parameter verification failed. 22561847f8eSopenharmony_ci * @throws { BusinessError } 100001 - Invalid ID. 22661847f8eSopenharmony_ci * @throws { BusinessError } 160002 - Timeout. 22761847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 22861847f8eSopenharmony_ci * @crossplatform 22961847f8eSopenharmony_ci * @atomicservice 23061847f8eSopenharmony_ci * @since 12 23161847f8eSopenharmony_ci */ 23261847f8eSopenharmony_ci function getSync(id: string, options?: SnapshotOptions): image.PixelMap; 23361847f8eSopenharmony_ci} 23461847f8eSopenharmony_ci 23561847f8eSopenharmony_ciexport default componentSnapshot; 236