• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 * @since 7
18 */
19declare enum ImageRenderMode {
20  /**
21   * Render according to the original image, including colors.
22   * @since 7
23   */
24  Original,
25
26  /**
27   * Render the image as a template image, ignoring the color information of the image.
28   * @since 7
29   */
30  Template,
31}
32
33/**
34 * @since 7
35 */
36declare enum ImageInterpolation {
37  /**
38   * Do not use interpolated image data.
39   * @since 7
40   */
41  None,
42
43  /**
44   * Low usage of interpolated image data.
45   * @since 7
46   */
47  Low,
48
49  /**
50   * Interpolated image data is used moderately.
51   * @since 7
52   */
53  Medium,
54
55  /**
56   * High usage of interpolated image data may affect the speed of image rendering.
57   * @since 7
58   */
59  High,
60}
61
62
63/**
64 * @since 7
65 */
66interface ImageInterface {
67  /**
68   * Set src to obtain images.
69   * @since 7
70   */
71  (src: string | PixelMap | Resource): ImageAttribute;
72}
73
74/**
75 * @since 7
76 */
77declare class ImageAttribute extends CommonMethod<ImageAttribute> {
78  /**
79   * Placeholder displayed on load
80   * @since 7
81   */
82  alt(value: string | Resource): ImageAttribute;
83
84  /**match Text Direction
85   * @since 7
86   */
87  matchTextDirection(value: boolean): ImageAttribute;
88
89  /**
90   * Indicates whether the image follows the text direction.
91   * @since 7
92   */
93  fitOriginalSize(value: boolean): ImageAttribute;
94
95  /**
96   * fill Color
97   * @since 7
98   */
99  fillColor(value: ResourceColor): ImageAttribute;
100
101  /**
102   * Sets the zoom type of an image.
103   * @since 7
104   */
105  objectFit(value: ImageFit): ImageAttribute;
106
107  /**
108   * Set the repeat style of the picture
109   * @since 7
110   */
111  objectRepeat(value: ImageRepeat): ImageAttribute;
112
113  /**
114   * Set the auto style of the picture
115   * @since 7
116   */
117  autoResize(value: boolean): ImageAttribute;
118
119  /**
120   * Sets the image rendering mode.
121   * @since 7
122   */
123  renderMode(value: ImageRenderMode): ImageAttribute;
124
125  /**
126   * Sets the interpolation effect of an image. The interpolation effect is only magnified for the image.
127   * @since 7
128   */
129  interpolation(value: ImageInterpolation): ImageAttribute;
130
131  /**
132   * Specifies the picture decoding size.
133   * The original picture is decoded into a picture of a specified size. The unit of the number type is px.
134   * @since 7
135   */
136  sourceSize(value: { width: number; height: number }): ImageAttribute;
137
138  /**
139   * Sets the synchronous or asynchronous mode for image loading.
140   * The default parameter type is bool, and the default value is false.
141   * @since 8
142   */
143  syncLoad(value: boolean): ImageAttribute;
144
145  /**
146   * This callback is triggered when an image is successfully loaded.
147   * The size of the image source that is successfully loaded is returned, in pixels.
148   * @since 7
149   */
150  onComplete(
151    callback: (event?: {
152      width: number;
153      height: number;
154      componentWidth: number;
155      componentHeight: number;
156      loadingStatus: number;
157    }) => void,
158  ): ImageAttribute;
159
160  /**
161   * This callback is triggered when an exception occurs during image loading.
162   * @since 7
163   */
164  onError(callback: (event?: { componentWidth: number; componentHeight: number }) => void): ImageAttribute;
165
166  /**
167   * When the loaded source file is a svg image, this callback is triggered when the playback of the svg image is complete.
168   * If the svg image is a wireless loop image, this callback is not triggered.
169   * @since 7
170   */
171  onFinish(event: () => void): ImageAttribute;
172}
173
174declare const Image: ImageInterface;
175declare const ImageInstance: ImageAttribute;
176