README.md
1# Image<a name="EN-US_TOPIC_0000001139841951"></a>
2
3- [Introduction](#section11660541593)
4- [Directory Structure](#section161941989596)
5- [Repositories Involved](#section1533973044317)
6
7## Introduction<a name="section11660541593"></a>
8
9The **image** repository provides easy-to-use APIs for developing image encoding and decoding features. Currently, the following image formats are supported: JPEG, PNG, BMP.
10
11**Figure 1** Image architecture<a name="fig99659301300"></a>
12
13
14## Directory Structure<a name="section161941989596"></a>
15
16The structure of the repository directory is as follows:
17
18```
19/foundation/multimedia/image
20├── frameworks # Framework code
21│ ├── innerkitsimpl # Native API implementation
22│ └── jni # JNI implementation
23├── ohos.build # Build configuration
24├── interfaces # External APIs
25│ ├── innerkits # APIs of other internal subsystems
26│ └── kits # Java APIs
27├── plugins # Image plug-in implementation
28│ ├── common # Common image plug-ins
29│ ├── manager # Image plug-in manager
30├── test # Test resources
31```
32
33## Repositories Involved<a name="section1533973044317"></a>
34
35hmf/multimedia/image
36
37
README_zh.md
1
2
3# Image组件
4
5- [简介](#introduction)
6- [目录](#index)
7- [使用说明](#usage-guidelines)
8 - [读像素到数组](#readPixelsToBuffer)
9 - [从区域读像素](readpixels)
10 - [写像素到区域](#writePixels)
11 - [写buffer到像素](#writeBufferToPixels)
12 - [获取图片基本信息](#getImageInfo1)
13 - [获取字节](#getBytesNumberPerRow)
14 - [获取位图buffer](#getPixelBytesNumber)
15 - [释放位图](#release1)
16 - [从图片源获取信息](#getImageInfo)
17 - [获取整型值](#getImagePropertyInt)
18 - [获取string类型值](#String)
19 - [创建位图](#createPixelMap)
20 - [更新数据](#updateData)
21 - [释放图片源实例](#release2)
22 - [打包图片](#packing)
23 - [释放packer实例](#release3)
24 - [createIncrementalSource](#createIncrementalSource)
25 - [创建ImageSource实例](#createImageSource2)
26 - [创建PixelMap实例](#createPixelMap2)
27 - [创建imagepacker实例](#createImagePacker2)
28
29## 简介<a name="introduction"></a>
30
31**image_standard仓库**提供了一系列易用的接口用于存放image的源码信息,提供创建图片源和位图管理能力,支持运行标准系统的设备使用。
32
33**图1** Image组件架构图
34
35
36
37
38
39支持能力列举如下:
40
41- 创建、释放位图。
42- 读写像素。
43- 获取位图信息。
44- 创建、释放图片源。
45- 获取图片源信息。
46- 创建、释放packer实例。
47
48## 目录<a name="index"></a>
49
50仓目录结构如下:
51
52```
53/foundation/multimedia/image_standard
54├── frameworks # 框架代码
55│ ├── innerkitsimpl # 内部接口实现
56│ │ └──iamge # Native 实现
57│ └── kitsimpl # 外部接口实现
58│ └──image # 外部 NAPI 实现
59├── interfaces # 接口代码
60│ ├── innerkits # 内部 Native 接口
61│ └── kits # 外部 JS 接口
62├── LICENSE # 证书文件
63├── ohos.build # 编译文件
64├── sa_profile # 服务配置文件
65└── services # 服务实现
66```
67
68## 使用说明<a name="usage-guidelines"></a>
69
70### 1.读像素到数组<a name="readPixelsToBuffer"></a>
71
72image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何将像素读到缓冲区。
73
74通过调用readPixelsToBuffer读pixels到buffer。
75
76```
77readPixelsToBuffer(dst: ArrayBuffer): Promise<void>;
78readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback<void>): void;
79```
80
81示例:
82
83```
84pixelmap.readPixelsToBuffer(readBuffer).then(() => {})
85```
86
87### 2.读pixels<a name="readPixels"></a>
88
89image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何按照区域读像素。
90
91通过调用readPixels读pixels。
92
93```
94readPixels(area: PositionArea): Promise<void>;
95readPixels(area: PositionArea, callback: AsyncCallback<void>): void;
96```
97
98示例:
99
100```
101pixelmap.readPixels(area).then(() => {})
102```
103
104### 3.写pixels<a name="writePixels"></a>
105
106image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何写像素。
107
108通过调用writepixels写到指定区域。
109
110```
111writePixels(area: PositionArea): Promise<void>;
112writePixels(area: PositionArea, callback: AsyncCallback<void>): void;
113```
114
115示例:
116
117```
118pixelmap.writePixels(area, () => {})
119```
120
121### 4.writeBufferToPixels<a name="writeBufferToPixels"></a>
122
123image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何将数据写进pixels。
124
125通过调用writeBufferToPixels写到pixel。
126
127```
128writeBufferToPixels(src: ArrayBuffer): Promise<void>;
129writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback<void>): void;
130```
131
132示例:
133
134```
135pixelmap.writeBufferToPixels(writeColor, () => {})
136```
137
138### 5.getImageInfo<a name="getImageInfo1"></a>
139
140image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何获取图片信息。
141
142通过调用getImageInfo获取图片基本信息。
143
1441.使用create通过属性创建pixelmap。
145
146```
147image.createPixelMap(color, opts, pixelmap =>{})
148```
149
1502.使用getImageInfo获取图片基本信息。
151
152```
153pixelmap.getImageInfo( imageInfo => {})
154```
155
156### 6.getBytesNumberPerRow<a name="getBytesNumberPerRow"></a>
157
158image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何获取每行字节数。
159
160通过调用getBytesNumberPerRow获取字节数。
161
162```
163getBytesNumberPerRow(): Promise<number>;
164getBytesNumberPerRow(callback: AsyncCallback<number>): void;
165```
166
167示例:
168
169```
170pixelmap.getBytesNumberPerRow((num) => {})
171```
172
173### 7.getPixelBytesNumber<a name="getPixelBytesNumber"></a>
174
175image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何获取buffer。
176
177通过调用getPixelBytesNumber获取buffer数。
178
179```
180getPixelBytesNumber(): Promise<number>;
181getPixelBytesNumber(callback: AsyncCallback<number>): void;
182```
183
184示例:
185
186```
187pixelmap.getPixelBytesNumber().then((num) => {
188 console.info('TC_026 num is ' + num)
189 expect(num == expectNum).assertTrue()
190 done()
191 })
192```
193
194### 8.release<a name="release1"></a>
195
196image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何释放pixelmap实例。
197
198通过调用release释放pixelmap。
199
2001.使用create通过属性创建pixelmap。
201
202```
203image.createPixelMap(color, opts, pixelmap =>{}
204```
205
2062.使用release释放pixelmap实例
207
208```
209pixelmap.release(()=>{
210 expect(true).assertTrue();
211 console.log('TC_027-1 suc');
212 done();
213 })
214```
215
216### 9.getImageInfo<a name="getImageInfo"></a>
217
218image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何根据特定数字获取图片信息。
219
220```
221getImageInfo(index: number, callback: AsyncCallback<ImageInfo>): void;
222getImageInfo(callback: AsyncCallback<ImageInfo>): void;
223getImageInfo(index?: number): Promise<ImageInfo>;
224```
225
2261.创建imagesource。
227
228```
229const imageSourceApi = image.createImageSource('/sdcard/test.jpg')
230```
231
2322.获取图片信息。
233
234```
235imageSourceApi.getImageInfo((imageInfo) => {
236 console.info('TC_045 imageInfo')
237 expect(imageInfo !== null).assertTrue()
238 done()
239 })
240```
241
242### 10.getImagePropertyInt<a name="getImagePropertyInt"></a>
243
244image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何根据索引获取属性的整型值。
245
246```
247getImagePropertyInt(index:number, key: string, defaultValue: number): Promise<number>;
248getImagePropertyInt(index:number, key: string, defaultValue: number, callback: AsyncCallback<number>): void;
249```
250
251### 11.getImagePropertyString<a name="String"></a>
252
253image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何根据索引获取属性的字符型值。
254
255```
256getImagePropertyString(key: string): Promise<string>;
257getImagePropertyString(key: string, callback: AsyncCallback<string>): void;
258```
259
260### 12.createPixelMap<a name="createPixelMap"></a>
261
262image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何创建pixelmap实例。
263
2641.使用createImageSource创建图片源。
265
266```
267const imageSourceApi = image.createImageSource('/sdcard/test.jpg')
268```
269
2702.使用createPixelMap创建pixelmap
271
272```
273imageSourceApi.createPixelMap(decodingOptions, (pixelmap) => {})
274```
275
276### 13.updateData<a name="updateData"></a>
277
278image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何更新图片数据源。
279
2801.使用createIncrementalSource创建imagesource。
281
282```
283const dataBuffer = new ArrayBuffer(96)
284const imageSourceIncrementalSApi = image.createIncrementalSource(dataBuffer)
285```
286
2872.使用updateData更新图片源。
288
289```
290imageSourceIncrementalSApi.updateData(array, false, (error, data) => {})
291```
292
293### 14.release<a name="release2"></a>
294
295image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何释放图片源实例。
296
297```
298release(): Promise<void>;
299```
300
301### 15.packing<a name="packing"></a>
302
303mage提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何压缩图片。
304
3051.使用createImageSource创建图片源。
306
307```
308const imageSourceApi = image.createImageSource('/sdcard/test.png')
309```
310
3112.创建packer实例。
312
313```
314imagePackerApi.packing(imageSourceApi, packOpts).then((data) => {})
315```
316
317### 16.release<a name="release3"></a>
318
319image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何释放packer实例。
320
3211.使用createImagePacker创建packer实例。
322
323```
324const imagePackerApi = image.createImagePacker()
325```
326
3272.使用release释放packer实例。
328
329```
330imagePackerApi.release()
331```
332
333### 17.createIncrementalSource<a name="createIncrementalSource"></a>
334
335image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何创建增量imagesource。
336
3371.创建buffer。
338
339```
340const data = new ArrayBuffer(96)
341```
342
3432.使用createIncrementalSource创建imagesource。
344
345```
346const imageSourceApi = image.createIncrementalSource(data)
347```
348
349### 18.创建ImageSource实例<a name="createImageSource2"></a>
350
351image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何通过不同方式创建imagesource。
352
3531.通过文件路径创建imagesource。
354
355```
356const imageSourceApi = image.createImageSource('/sdcard/test.jpg')
357```
358
3591.通过fd创建imagesource。
360
361```
362const imageSourceApi = image.createImageSource(fd)
363```
364
3653.通过buffer创建imagesource。
366
367```
368const data = new ArrayBuffer(112)
369const imageSourceApi = image.createImageSource(data)
370```
371
372### 19.创建PixelMap实例<a name="createPixelMap2"></a>
373
374image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何通过属性创建pixelmap。
375
3761.设置属性。
377
378```
379const Color = new ArrayBuffer(96)
380 let opts = {
381 alphaType: 0,
382 editable: true,
383 pixelFormat: 4,
384 scaleMode: 1,
385 size: { height: 2, width: 3 },
386 }
387```
388
3892.调用createpixelmap通过属性创建pixelmap实例。
390
391```
392image.createPixelMap(Color, opts)
393 .then((pixelmap) => {
394 expect(pixelmap !== null).assertTrue()
395 console.info('TC_001 success')
396 done()
397 })
398```
399
400### 20.创建imagepacker实例<a name="createImagePacker2"></a>
401
402image提供了操作imagepacker的接口,以下展示了如何通过属性创建imagepacker。
403
4041.创建imagesource。
405
406```
407const imageSourceApi = image.createImageSource('/sdcard/test.png')
408```
409
4102.创建imagepacker。
411
412```
413const imagePackerApi = image.createImagePacker()
414```
415
416