1e41f4b71Sopenharmony_ci# XComponent
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **\<XComponent>** can accept and display the EGL/OpenGL ES and media data input.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ciChild components are not supported when **type** is set to **"surface"**.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciSince API version 9, child components are supported when **type** is set to **"component"**.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## APIs
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci### XComponent
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciXComponent(value: {id: string, type: string, libraryname?: string, controller?: XComponentController})
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Parameters**
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci| Name     | Type                                     | Mandatory| Description                                                        |
24e41f4b71Sopenharmony_ci| ----------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
25e41f4b71Sopenharmony_ci| id          | string                                        | Yes  | Unique ID of the component. The value can contain a maximum of 128 characters.                   |
26e41f4b71Sopenharmony_ci| type        | string                                        | Yes  | Type of the component. The options are as follows:<br>- **"surface"**: The custom content is displayed individually on the screen. This option is used for displaying EGL/OpenGL ES and media data.<br>- **"component"**<sup>9+</sup>: The component becomes a container where non-UI logic can be executed to dynamically load the display content.<br>Any other value evaluates to **"surface"**.|
27e41f4b71Sopenharmony_ci| libraryname | string                                        | No  | Name of the dynamic library generated after compilation at the application native layer. This parameter is valid only when **type** is **"surface"**.|
28e41f4b71Sopenharmony_ci| controller  | [XComponentcontroller](#xcomponentcontroller) | No  | Controller bound to the component, which can be used to invoke methods of the component. This parameter is valid only when the component type is **"surface"**.|
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci### XComponent<sup>10+</sup>
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ciXComponent(value: {id: string, type: XComponentType, libraryname?: string, controller?: XComponentController})
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci**Parameters**
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci| Name     | Type                                     | Mandatory| Description                                                        |
37e41f4b71Sopenharmony_ci| ----------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
38e41f4b71Sopenharmony_ci| id          | string                                        | Yes  | Unique ID of the component. The value can contain a maximum of 128 characters.                   |
39e41f4b71Sopenharmony_ci| type        | [XComponentType](#xcomponenttype10)   | Yes  | Type of the component.                                |
40e41f4b71Sopenharmony_ci| libraryname | string                                        | No  | Name of the dynamic library generated after compilation at the application native layer. This parameter is valid only when **type** is **SURFACE** or **TEXTURE**.|
41e41f4b71Sopenharmony_ci| controller  | [XComponentcontroller](#xcomponentcontroller) | No  | Controller bound to the component, which can be used to invoke methods of the component. This parameter is valid only when **type** is **SURFACE** or **TEXTURE**.|
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci## XComponentType<sup>10+</sup>
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci| Name     | Description                                                        |
46e41f4b71Sopenharmony_ci| --------- | ------------------------------------------------------------ |
47e41f4b71Sopenharmony_ci| SURFACE   | The custom content is displayed individually on the screen. This option is used for displaying EGL/OpenGL ES and media data.|
48e41f4b71Sopenharmony_ci| COMPONENT | The component becomes a container where non-UI logic can be executed to dynamically load the display content.|
49e41f4b71Sopenharmony_ci| TEXTURE   | The custom content of the component is grouped and displayed together with content of the component.|
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci> **NOTE**
52e41f4b71Sopenharmony_ci>
53e41f4b71Sopenharmony_ci> When **type** is set to **COMPONENT("component")**, the **\<XComponent>** functions as a container, where child components are laid out vertically.
54e41f4b71Sopenharmony_ci>
55e41f4b71Sopenharmony_ci> - Vertical alignment: [FlexAlign](ts-appendix-enums.md#flexalign).Start
56e41f4b71Sopenharmony_ci> - Horizontal alignment: [FlexAlign](ts-appendix-enums.md#flexalign).Center
57e41f4b71Sopenharmony_ci>
58e41f4b71Sopenharmony_ci> The component does not respond to any events.
59e41f4b71Sopenharmony_ci>
60e41f4b71Sopenharmony_ci> Layout changes and event responses can be set by mounting child components.
61e41f4b71Sopenharmony_ci>
62e41f4b71Sopenharmony_ci> The non-UI logic written internally needs to be encapsulated in one or more functions.
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci## Attributes
65e41f4b71Sopenharmony_ci- You can customize the content displayed in the **\<XComponent>**. Depending on the **type** settings, the support for the universal attributes [background](ts-universal-attributes-background.md), [opacity](ts-universal-attributes-opacity.md), and [image effects](ts-universal-attributes-image-effect.md) varies.
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci- When **type** is set to **SURFACE("surface")**, only the **shadow** attribute of [image effects](ts-universal-attributes-image-effect.md). For configuration of other attributes, you are advised to use the APIs provided by EGL/OpenGL ES instead.
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci  > **NOTE**<br>
70e41f4b71Sopenharmony_ci  >
71e41f4b71Sopenharmony_ci  > Since API version 11, when **type** is set to **SURFACE("surface")**, the [backgroundColor](ts-universal-attributes-background.md#backgroundcolor) attribute is supported.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci- When **type** is set to **COMPONENT("component")**, only the **shadow** attribute of [image effects](ts-universal-attributes-image-effect.md). For configuration of other attributes, you are advised to mount child components.
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci- When **type** is set to **TEXTURE**, the **shadow** attribute of [image effects](ts-universal-attributes-image-effect.md), [backgroundColor](ts-universal-attributes-background.md#backgroundcolor), and [opacity](ts-universal-attributes-opacity.md) are supported. For configuration of other attributes, you are advised to use the APIs provided by EGL/OpenGL ES instead.
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci### enableAnalyzer<sup>12+</sup>
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_cienableAnalyzer(enable: boolean)
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ciSpecifies whether to enable the AI image analyzer. This attribute must be used together with[StartImageAnalyzer](#startimageanalyzer12) and [StopImageAnalyzer](#stopimageanalyzer12) in **XComponentController**.
82e41f4b71Sopenharmony_ciThis attribute cannot be used together with the [overlay](ts-universal-attributes-overlay.md) attribute. If they are set at the same time, the **CustomBuilder** attribute in **overlay** has no effect. This feature depends on device capabilities.
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**Parameters**
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
91e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
92e41f4b71Sopenharmony_ci| enable | boolean | Yes| Whether to enable the AI image analyzer.|
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci  > **NOTE**<br>
95e41f4b71Sopenharmony_ci  >
96e41f4b71Sopenharmony_ci  > This API has effect only when **type** is set to **SURFACE** or **TEXTURE**.
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci## Events
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ciWhen **type** is set to **SURFACE("surface")** or **TEXTURE**, the [universal events](ts-universal-events-click.md) are supported since API version 12, subject to the following constraints:
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci- The following events, which are mutually exclusive with the corresponding NDK APIs, are available only when **libraryname** is not set: [click event](ts-universal-events-click.md), [touch event](ts-universal-events-touch.md), [show/hide event](ts-universal-events-show-hide.md), [key event](ts-universal-events-key.md), [focus event](ts-universal-focus-event.md), and [mouse event](ts-universal-mouse-key.md).
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci- Other universal events do not have corresponding NDK APIs; therefore, they are available regardless of whether **libraryname** is set.
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ciWhen **type** is set to **SURFACE("surface")** or **TEXTURE**, the following events are supported.
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci### onLoad
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_cionLoad(callback: (event?: object) => void )
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ciTriggered when the plug-in is loaded.
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci**Parameters**
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory  | Description                                      |
117e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------------------------- |
118e41f4b71Sopenharmony_ci| event | object | No   | Context of the **\<XComponent>** object. The APIs contained in the context are defined at the C++ layer by developers.|
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci### onDestroy
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_cionDestroy(event: () => void )
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ciTriggered when the plug-in is destroyed.
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci## XComponentController
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ciDefines the controller of the **\<XComponent>**. You can bind the controller to the **\<XComponent>** to invoke the methods of the component through the controller.
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci### Creating an Object
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci```
133e41f4b71Sopenharmony_cixcomponentController: XComponentController = new XComponentController()
134e41f4b71Sopenharmony_ci```
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci### getXComponentSurfaceId
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_cigetXComponentSurfaceId(): string
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ciObtains the ID of the surface held by the **\<XComponent>**, which can then be used for @ohos APIs. For details, see [Camera Management](../../apis-camera-kit/js-apis-camera.md). This API works only when **type** of the **\<XComponent>** is set to **SURFACE("surface")** or **TEXTURE**.
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci**Return value**
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci| Type    | Description                     |
145e41f4b71Sopenharmony_ci| ------ | ----------------------- |
146e41f4b71Sopenharmony_ci| string | ID of the surface held by the **\<XComponent>**.|
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci### setXComponentSurfaceSize<sup>(deprecated)</sup>
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_cisetXComponentSurfaceSize(value: {surfaceWidth: number, surfaceHeight: number}): void
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ciSets the width and height of the surface held by the **\<XComponent>**. This API works only when **type** of the **\<XComponent>** is set to **SURFACE("surface")** or **TEXTURE**.
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ciThis API is deprecated since API version 12. You are advised to use [setXComponentSurfaceRect](#setxcomponentsurfacerect12) instead.
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci**Parameters**
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci| Name          | Type  | Mandatory  | Description                     |
160e41f4b71Sopenharmony_ci| ------------- | ------ | ---- | ----------------------- |
161e41f4b71Sopenharmony_ci| surfaceWidth  | number | Yes   | Width of the surface held by the **\<XComponent>**.|
162e41f4b71Sopenharmony_ci| surfaceHeight | number | Yes   | Height of the surface held by the **\<XComponent>**.|
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci### getXComponentContext
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_cigetXComponentContext(): Object
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ciObtains the context of an **\<XComponent>** object. This API works only when **type** of the **\<XComponent>** is set to **SURFACE("surface")** or **TEXTURE**.
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci**Return value**
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci| Type  | Description                                                        |
174e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ |
175e41f4b71Sopenharmony_ci| Object | Context of the **\<XComponent>** object. The APIs contained in the context are defined by developers. The context is passed in as the first parameter of the **onLoad** callback.|
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci### setXComponentSurfaceRect<sup>12+</sup>
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_cisetXComponentSurfaceRect(rect: SurfaceRect): void
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ciSets the rectangle for the surface held by the **\<XComponent>**. This API works only when type of the **\<XComponent>** is set to **SURFACE("surface")** or **TEXTURE**.
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci**Parameters**
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci| Name| Type                            | Mandatory| Description                             |
186e41f4b71Sopenharmony_ci| ------ | ------------------------------------ | ---- | --------------------------------- |
187e41f4b71Sopenharmony_ci| rect   | [SurfaceRect](#surfacerect12) | Yes  | Rectangle of the surface held by the **\<XComponent>**.|
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci> **NOTE**<br>
190e41f4b71Sopenharmony_ci>
191e41f4b71Sopenharmony_ci> If **offsetX** or **offsetY** in the **rect** parameter is not set, the surface rectangle is centered along the x-axis or y-axis relative to the upper left corner of the **\<XComponent>**.
192e41f4b71Sopenharmony_ci>
193e41f4b71Sopenharmony_ci> If **surfaceWidth** and **surfaceHeight** in the **rect** parameter are set to **0** or a negative value, this API has no effect.
194e41f4b71Sopenharmony_ci>
195e41f4b71Sopenharmony_ci> This API has a higher priority than attributes that can change the content offset and size, such as [border](ts-universal-attributes-border.md#border) and [padding](ts-universal-attributes-size.md#padding).
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ci### getXComponentSurfaceRect<sup>12+</sup>
198e41f4b71Sopenharmony_ci
199e41f4b71Sopenharmony_cigetXComponentSurfaceRect(): SurfaceRect
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ciObtains the rectangle of the surface held by the **\<XComponent>**. This API works only when type of the **\<XComponent>** is set to **SURFACE("surface")** or **TEXTURE**.
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci**Return value**
204e41f4b71Sopenharmony_ci
205e41f4b71Sopenharmony_ci| Type                                | Description                                 |
206e41f4b71Sopenharmony_ci| ------------------------------------ | ------------------------------------- |
207e41f4b71Sopenharmony_ci| [SurfaceRect](#surfacerect12) | Rectangle of the surface held by the **\<XComponent>**.|
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci### onSurfaceCreated<sup>12+</sup>
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_cionSurfaceCreated(surfaceId: string): void
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ciTriggered when the surface held by the **\<XComponent>** is created. This API works only when **type** of the **\<XComponent>** is set to **SURFACE("surface")** or **TEXTURE**.
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ci**Parameters**
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci| Name   | Type| Mandatory| Description                                             |
218e41f4b71Sopenharmony_ci| --------- | -------- | ---- | ------------------------------------------------- |
219e41f4b71Sopenharmony_ci| surfaceId | string   | Yes  | ID of the surface held by the **\<XComponent>**.|
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci> **NOTE**<br>
222e41f4b71Sopenharmony_ci>
223e41f4b71Sopenharmony_ci> The callback is triggered only when the **libraryname** parameter is not set for the **\<XComponent>**.
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci### onSurfaceChanged<sup>12+</sup>
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_cionSurfaceChanged(surfaceId: string, rect: SurfaceRect): void
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ciTriggered when the surface held by the **\<XComponent>** has its size changed (including the time when the **\<XComponent>** is created with the specified size). This API works only when **type** of the **\<XComponent>** is set to **SURFACE("surface")** or **TEXTURE**.
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci**Parameters**
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci| Name   | Type                             | Mandatory| Description                                                   |
234e41f4b71Sopenharmony_ci| --------- | ------------------------------------- | ---- | ------------------------------------------------------- |
235e41f4b71Sopenharmony_ci| surfaceId | string                                | Yes  | ID of the surface held by the **\<XComponent>**.      |
236e41f4b71Sopenharmony_ci| rect      | [SurfaceRect](#surfacerect12) | Yes  | Rectangle for displaying the surface held by the **\<XComponent>**.|
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ci> **NOTE**<br>
239e41f4b71Sopenharmony_ci>
240e41f4b71Sopenharmony_ci> The callback is triggered only when the **libraryname** parameter is not set for the **\<XComponent>**.
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci### onSurfaceDestroyed<sup>12+</sup>
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_cionSurfaceDestroyed(surfaceId: string): void
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ciTriggered when the surface held by the **\<XComponent>** is destroyed. This API works only when **type** of the **\<XComponent>** is set to **SURFACE("surface")** or **TEXTURE**.
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci**Parameters**
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_ci| Name   | Type| Mandatory| Description                                             |
251e41f4b71Sopenharmony_ci| --------- | -------- | ---- | ------------------------------------------------- |
252e41f4b71Sopenharmony_ci| surfaceId | string   | Yes  | ID of the surface held by the **\<XComponent>**.|
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci> **NOTE**<br>
255e41f4b71Sopenharmony_ci>
256e41f4b71Sopenharmony_ci> The callback is triggered only when the **libraryname** parameter is not set for the **\<XComponent>**.
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci### SurfaceRect<sup>12+</sup>
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_ciDescribes the rectangle of the surface held by the **\<XComponent>**.
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci| Name         | Type  | Mandatory| Description                                                        |
263e41f4b71Sopenharmony_ci| ------------- | ------ | ---- | ------------------------------------------------------------ |
264e41f4b71Sopenharmony_ci| offsetX       | number | No  | X coordinate of the surface rectangle relative to the upper left corner of the **\<XComponent>**.<br>Unit: px|
265e41f4b71Sopenharmony_ci| offsetY       | number | No  | Y coordinate of the surface rectangle relative to the upper left corner of the **\<XComponent>**.<br>Unit: px|
266e41f4b71Sopenharmony_ci| surfaceWidth  | number | Yes  | Width of the surface rectangle.<br>Unit: px                           |
267e41f4b71Sopenharmony_ci| surfaceHeight | number | Yes  | Height of the surface rectangle.<br>Unit: px                           |
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci### startImageAnalyzer<sup>12+</sup>
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_cistartImageAnalyzer(config: ImageAnalyzerConfig): Promise\<void>
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_ciStarts AI image analysis in the given settings. Before calling this API, make sure the AI image analyzer is [enabled](#enableanalyzer12).<br>Because the image frame used for analysis is the one captured when this API is called, pay attention to the invoking time of this API.<br>If this API is repeatedly called before the execution is complete, an error callback is triggered.
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci> **NOTE**<br>
276e41f4b71Sopenharmony_ci> 
277e41f4b71Sopenharmony_ci> The image analysis type cannot be dynamically modified.
278e41f4b71Sopenharmony_ci> This API depends on device capabilities. If it is called on an incompatible device, an error code is returned.
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci**Parameters**
283e41f4b71Sopenharmony_ci
284e41f4b71Sopenharmony_ci| Name| Type     | Mandatory| Description                                                                  |
285e41f4b71Sopenharmony_ci| ------ | --------- | ---- | ---------------------------------------------------------------------- |
286e41f4b71Sopenharmony_ci| config   | [ImageAnalyzerConfig](ts-image-common.md#imageanalyzerconfig12) | Yes  | Settings of the AI image analyzer.|
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci**Return value**
289e41f4b71Sopenharmony_ci
290e41f4b71Sopenharmony_ci| Type             | Description                                |
291e41f4b71Sopenharmony_ci| ----------------- | ------------------------------------ |
292e41f4b71Sopenharmony_ci| Promise\<void>  | Promise used to return the result.|
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci**Error codes**
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_ciFor details about the error codes, see [AI Image Analyzer Error Codes](../errorcode-image-analyzer.md).
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ci| ID| Error Message                                     |
299e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- |
300e41f4b71Sopenharmony_ci| 110001 | AI analysis is unsupported.               |
301e41f4b71Sopenharmony_ci| 110002 | AI analysis is ongoing.  |
302e41f4b71Sopenharmony_ci| 110003 | AI analysis is stopped.  |
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci### stopImageAnalyzer<sup>12+</sup>
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_cistopImageAnalyzer(): void
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ciStops AI image analysis. The content displayed by the AI image analyzer will be destroyed.
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ci> **NOTE**<br>
311e41f4b71Sopenharmony_ci> 
312e41f4b71Sopenharmony_ci> If this API is called when the **startImageAnalyzer** API has not yet returned any result, an error callback is triggered.
313e41f4b71Sopenharmony_ci> This feature depends on device capabilities.
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ci## Example
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ciYou can preview how this component looks on a real device, but not in the DevEco Studio Previewer.
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_ci### Example 1
322e41f4b71Sopenharmony_ci
323e41f4b71Sopenharmony_ci```ts
324e41f4b71Sopenharmony_ci// xxx.ets
325e41f4b71Sopenharmony_ci@Entry
326e41f4b71Sopenharmony_ci@Component
327e41f4b71Sopenharmony_cistruct PreviewArea {
328e41f4b71Sopenharmony_ci  private surfaceId: string = ''
329e41f4b71Sopenharmony_ci  private xComponentContext: Record<string, () => void> = {}
330e41f4b71Sopenharmony_ci  xComponentController: XComponentController = new XComponentController()
331e41f4b71Sopenharmony_ci  @State rect: SurfaceRect | null = null
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci  build() {
334e41f4b71Sopenharmony_ci    Column() {
335e41f4b71Sopenharmony_ci      Text(JSON.stringify(this.rect))
336e41f4b71Sopenharmony_ci        .fontSize(12)
337e41f4b71Sopenharmony_ci      XComponent({
338e41f4b71Sopenharmony_ci        id: 'xcomponent',
339e41f4b71Sopenharmony_ci        type: XComponentType.SURFACE,
340e41f4b71Sopenharmony_ci        controller: this.xComponentController
341e41f4b71Sopenharmony_ci      })
342e41f4b71Sopenharmony_ci        .onLoad(() => {
343e41f4b71Sopenharmony_ci          this.surfaceId = this.xComponentController.getXComponentSurfaceId()
344e41f4b71Sopenharmony_ci          this.xComponentContext = this.xComponentController.getXComponentContext() as Record<string, () => void>
345e41f4b71Sopenharmony_ci          let surfaceRect: SurfaceRect = { offsetX: 20, offsetY: 20, surfaceWidth: 500, surfaceHeight: 500 }
346e41f4b71Sopenharmony_ci          this.xComponentController.setXComponentSurfaceRect(surfaceRect)
347e41f4b71Sopenharmony_ci          this.rect = this.xComponentController.getXComponentSurfaceRect()
348e41f4b71Sopenharmony_ci        })
349e41f4b71Sopenharmony_ci        .width('640px')
350e41f4b71Sopenharmony_ci        .height('480px')
351e41f4b71Sopenharmony_ci    }
352e41f4b71Sopenharmony_ci    .position({ x: 0, y: 48 })
353e41f4b71Sopenharmony_ci  }
354e41f4b71Sopenharmony_ci}
355e41f4b71Sopenharmony_ci```
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci### Example 2
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci```ts
360e41f4b71Sopenharmony_ci// xxx.ets
361e41f4b71Sopenharmony_ciclass CustomXComponentController extends XComponentController {
362e41f4b71Sopenharmony_ci  onSurfaceCreated(surfaceId: string): void {
363e41f4b71Sopenharmony_ci    console.log(`onSurfaceCreated surfaceId: ${surfaceId}`)
364e41f4b71Sopenharmony_ci  }
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ci  onSurfaceChanged(surfaceId: string, rect: SurfaceRect): void {
367e41f4b71Sopenharmony_ci    console.log(`onSurfaceChanged surfaceId: ${surfaceId}, rect: ${JSON.stringify(rect)}}`)
368e41f4b71Sopenharmony_ci  }
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci  onSurfaceDestroyed(surfaceId: string): void {
371e41f4b71Sopenharmony_ci    console.log(`onSurfaceDestroyed surfaceId: ${surfaceId}`)
372e41f4b71Sopenharmony_ci  }
373e41f4b71Sopenharmony_ci}
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci@Entry
376e41f4b71Sopenharmony_ci@Component
377e41f4b71Sopenharmony_cistruct SurfaceCallbackDemo {
378e41f4b71Sopenharmony_ci  xComponentController: XComponentController = new CustomXComponentController()
379e41f4b71Sopenharmony_ci  @State xcWidth: string = "320px"
380e41f4b71Sopenharmony_ci  @State xcHeight: string = "480px"
381e41f4b71Sopenharmony_ci
382e41f4b71Sopenharmony_ci  build() {
383e41f4b71Sopenharmony_ci    Column() {
384e41f4b71Sopenharmony_ci      Button("change size")
385e41f4b71Sopenharmony_ci        .onClick(() => {
386e41f4b71Sopenharmony_ci          this.xcWidth = "640px"
387e41f4b71Sopenharmony_ci          this.xcHeight = "960px"
388e41f4b71Sopenharmony_ci        })
389e41f4b71Sopenharmony_ci      XComponent({
390e41f4b71Sopenharmony_ci        id: 'xcomponent',
391e41f4b71Sopenharmony_ci        type: XComponentType.SURFACE,
392e41f4b71Sopenharmony_ci        controller: this.xComponentController
393e41f4b71Sopenharmony_ci      })
394e41f4b71Sopenharmony_ci        .width(this.xcWidth)
395e41f4b71Sopenharmony_ci        .height(this.xcHeight)
396e41f4b71Sopenharmony_ci    }
397e41f4b71Sopenharmony_ci    .width("100%")
398e41f4b71Sopenharmony_ci  }
399e41f4b71Sopenharmony_ci}
400e41f4b71Sopenharmony_ci```
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci### Example 3
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ciThis example shows how to use the AI image analyzer.
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci```ts
407e41f4b71Sopenharmony_ci// xxx.ets
408e41f4b71Sopenharmony_ci@Entry
409e41f4b71Sopenharmony_ci@Component
410e41f4b71Sopenharmony_cistruct ImageAnalyzerExample {
411e41f4b71Sopenharmony_ci  xComponentController: XComponentController = new XComponentController()
412e41f4b71Sopenharmony_ci  private config: ImageAnalyzerConfig = {
413e41f4b71Sopenharmony_ci    types: [ImageAnalyzerType.SUBJECT, ImageAnalyzerType.TEXT]
414e41f4b71Sopenharmony_ci  }
415e41f4b71Sopenharmony_ci
416e41f4b71Sopenharmony_ci  build() {
417e41f4b71Sopenharmony_ci    Column() {
418e41f4b71Sopenharmony_ci      Button('start')
419e41f4b71Sopenharmony_ci        .width(80)
420e41f4b71Sopenharmony_ci        .height(80)
421e41f4b71Sopenharmony_ci        .onClick(() => {
422e41f4b71Sopenharmony_ci          this.xComponentController.startImageAnalyzer(this.config)
423e41f4b71Sopenharmony_ci            .then(() => {
424e41f4b71Sopenharmony_ci              console.log("analysis complete")
425e41f4b71Sopenharmony_ci            })
426e41f4b71Sopenharmony_ci            .catch((error: BusinessError) => {
427e41f4b71Sopenharmony_ci              console.log("error code: " + error.code)
428e41f4b71Sopenharmony_ci            })
429e41f4b71Sopenharmony_ci        })
430e41f4b71Sopenharmony_ci      Button('stop')
431e41f4b71Sopenharmony_ci        .width(80)
432e41f4b71Sopenharmony_ci        .height(80)
433e41f4b71Sopenharmony_ci        .onClick(() => {
434e41f4b71Sopenharmony_ci          this.xComponentController.stopImageAnalyzer()
435e41f4b71Sopenharmony_ci        })
436e41f4b71Sopenharmony_ci      XComponent({
437e41f4b71Sopenharmony_ci        id: 'xcomponent',
438e41f4b71Sopenharmony_ci        type: XComponentType.SURFACE,
439e41f4b71Sopenharmony_ci        controller: this.xComponentController
440e41f4b71Sopenharmony_ci      })
441e41f4b71Sopenharmony_ci        .enableAnalyzer(true)
442e41f4b71Sopenharmony_ci        .width('640px')
443e41f4b71Sopenharmony_ci        .height('480px')
444e41f4b71Sopenharmony_ci    }
445e41f4b71Sopenharmony_ci    .width("100%")
446e41f4b71Sopenharmony_ci  }
447e41f4b71Sopenharmony_ci}
448e41f4b71Sopenharmony_ci```
449