• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# image_packer_mdk.h
2<!--Kit: Image Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @aulight02-->
5<!--SE: @liyang_bryan-->
6<!--TSE: @xchaosioda-->
7
8## Overview
9
10The file declares the APIs used to pack an image or a PixelMap into a buffer or file.
11
12The packing process is as follows:
13
141. Call **OH_ImagePacker_Create** to create an ImagePacker object.
15
162. Call **OH_ImagePacker_InitNative** to convert the ImagePacker object to an ImagePacker_Native object.
17
183. Call **OH_ImagePacker_PackToData** or OH_ImagePacker_PackToFile to pack the source into the target area with the specified packing options.
19
204. Call **OH_ImagePacker_Release** to release an ImagePacker_Native object.
21
22**Library**: libimage_packer_ndk.z.so
23
24**System capability**: SystemCapability.Multimedia.Image
25
26**Since**: 11
27
28**Related module**: [Image](capi-image.md)
29
30## Summary
31
32### Structs
33
34| Name| typedef Keyword| Description|
35| -- | -- | -- |
36| [ImagePacker_Opts_](capi-image-imagepacker-opts-.md) | ImagePacker_Opts | Describes the image packing options.|
37| [ImagePacker_Native_](capi-image-imagepacker-native-.md) | ImagePacker_Native | Describes the ImagePacker instance at the native layer.|
38
39### Functions
40
41| Name| Description|
42| -- | -- |
43| [int32_t OH_ImagePacker_Create(napi_env env, napi_value *res)](#oh_imagepacker_create) | Obtains an ImagePacker object at the JavaScript native layer.|
44| [ImagePacker_Native* OH_ImagePacker_InitNative(napi_env env, napi_value packer)](#oh_imagepacker_initnative) | Converts an ImagePacker object at the JavaScript native layer into an ImagePacker_Native object.|
45| [int32_t OH_ImagePacker_PackToData(ImagePacker_Native* native, napi_value source,ImagePacker_Opts* opts, uint8_t* outData, size_t* size)](#oh_imagepacker_packtodata) | Packs a PixelMap object or an ImagePacker object at the JavaScript native layer to a buffer (defined by **outData**) based on the specified ImagePacker_Opts struct.|
46| [int32_t OH_ImagePacker_PackToFile(ImagePacker_Native* native, napi_value source,ImagePacker_Opts* opts, int fd)](#oh_imagepacker_packtofile) | Packs a PixelMap object or an ImagePacker object at the JavaScript native layer to a file based on the specified ImagePacker_Opts struct.|
47| [int32_t OH_ImagePacker_Release(ImagePacker_Native* native)](#oh_imagepacker_release) | Releases an [ImagePacker_Native](capi-image-imagepacker-native-.md) object.<br>It is not used to release the ImagePacker object at the JavaScript native layer.|
48
49## Function Description
50
51### OH_ImagePacker_Create()
52
53```
54int32_t OH_ImagePacker_Create(napi_env env, napi_value *res)
55```
56
57**Description**
58
59Obtains an ImagePacker object at the JavaScript native layer.
60
61**Since**: 11
62
63
64**Parameters**
65
66| Name| Description|
67| -- | -- |
68| napi_env env | Pointer to the JNI environment.|
69| napi_value *res | Pointer to an ImagePacker object at the JavaScript native layer.|
70
71**Returns**
72
73| Type| Description|
74| -- | -- |
75| int32_t | Result code defined in [IRNdkErrCode](capi-image-mdk-common-h.md#irndkerrcode):<br>**IMAGE_RESULT_SUCCESS**: The operation is successful.<br>**IMAGE_RESULT_INVALID_PARAMETER**: A parameter is invalid.|
76
77### OH_ImagePacker_InitNative()
78
79```
80ImagePacker_Native* OH_ImagePacker_InitNative(napi_env env, napi_value packer)
81```
82
83**Description**
84
85Converts an ImagePacker object at the JavaScript native layer into an ImagePacker_Native object.
86
87**Since**: 11
88
89
90**Parameters**
91
92| Name| Description|
93| -- | -- |
94| napi_env env | Pointer to the JNI environment.|
95| napi_value packer | ImagePacker object at the JavaScript native layer.|
96
97**Returns**
98
99| Type| Description|
100| -- | -- |
101| [ImagePacker_Native](capi-image-imagepacker-native-.md)* | Pointer to an ImagePacker_Native object. If the operation fails, a null pointer is returned.|
102
103**See also**
104
105[OH_ImagePacker_Release](#oh_imagepacker_release)
106
107### OH_ImagePacker_PackToData()
108
109```
110int32_t OH_ImagePacker_PackToData(ImagePacker_Native* native, napi_value source,ImagePacker_Opts* opts, uint8_t* outData, size_t* size)
111```
112
113**Description**
114
115Packs a PixelMap object or an ImagePacker object at the JavaScript native layer to a buffer (defined by **outData**) based on the specified ImagePacker_Opts struct.
116
117**Since**: 11
118
119
120**Parameters**
121
122| Name| Description|
123| -- | -- |
124| [ImagePacker_Native](capi-image-imagepacker-native-.md)* native | Pointer to an ImagePacker_Native object.|
125| napi_value source | PixelMap object or ImageSource object at the JavaScript native layer.|
126| [ImagePacker_Opts](capi-image-imagepacker-opts-.md)* opts | Pointer to the packing options.|
127| uint8_t* outData | Pointer to the output buffer.|
128| size_t* size | Pointer to the size of the buffer.|
129
130**Returns**
131
132| Type| Description|
133| -- | -- |
134| int32_t | Result code defined in [IRNdkErrCode](capi-image-mdk-common-h.md#irndkerrcode):<br>**IMAGE_RESULT_SUCCESS**: The operation is successful.<br>  **IMAGE_RESULT_INVALID_PARAMETER**: A parameter is invalid.<br> **ERR_IMAGE_DATA_ABNORMAL**: The output buffer is abnormal.<br>  **ERR_IMAGE_MISMATCHED_FORMAT**: The format is incorrect.<br>  **ERR_IMAGE_MALLOC_ABNORMAL**: An error occurs in the malloc internal buffer.<br>  **ERR_IMAGE_DECODE_ABNORMAL**: An internal error occurs during codec initialization.<br>**ERR_IMAGE_ENCODE_FAILED**: An error occurs during encoding.|
135
136**See also**
137
138[OH_ImagePacker_PackToFile](#oh_imagepacker_packtofile)
139
140### OH_ImagePacker_PackToFile()
141
142```
143int32_t OH_ImagePacker_PackToFile(ImagePacker_Native* native, napi_value source,ImagePacker_Opts* opts, int fd)
144```
145
146**Description**
147
148Packs a PixelMap object or an ImagePacker object at the JavaScript native layer to a file based on the specified ImagePacker_Opts struct.
149
150**Since**: 11
151
152
153**Parameters**
154
155| Name| Description|
156| -- | -- |
157| [ImagePacker_Native](capi-image-imagepacker-native-.md)* native | Pointer to an ImagePacker_Native object.|
158| napi_value source | PixelMap object or ImageSource object at the JavaScript native layer.|
159| [ImagePacker_Opts](capi-image-imagepacker-opts-.md)* opts | Pointer to the packing options.|
160| int fd | File descriptor of the output file.|
161
162**Returns**
163
164| Type| Description|
165| -- | -- |
166| int32_t | Result code defined in [IRNdkErrCode](capi-image-mdk-common-h.md#irndkerrcode):<br>**IMAGE_RESULT_SUCCESS**: The operation is successful.<br>  **IMAGE_RESULT_INVALID_PARAMETER**: A parameter is invalid.<br> **ERR_IMAGE_DATA_ABNORMAL**: The output buffer is abnormal.<br>  **ERR_IMAGE_MISMATCHED_FORMAT**: The format is incorrect.<br>  **ERR_IMAGE_MALLOC_ABNORMAL**: An error occurs in the malloc internal buffer.<br>  **ERR_IMAGE_DECODE_ABNORMAL**: An internal error occurs during codec initialization.<br>**ERR_IMAGE_ENCODE_FAILED**: An error occurs during encoding.|
167
168**See also**
169
170[OH_ImagePacker_PackToData](#oh_imagepacker_packtodata)
171
172### OH_ImagePacker_Release()
173
174```
175int32_t OH_ImagePacker_Release(ImagePacker_Native* native)
176```
177
178**Description**
179
180Releases an [ImagePacker_Native](capi-image-imagepacker-native-.md) object.
181
182It is not used to release the ImagePacker object at the JavaScript native layer.
183
184It is parsed by calling [OH_ImagePacker_InitNative](#oh_imagepacker_initnative).
185
186**Since**: 11
187
188
189**Parameters**
190
191| Name| Description|
192| -- | -- |
193| [ImagePacker_Native](capi-image-imagepacker-native-.md)* native | Pointer to an ImagePacker_Native object.|
194
195**Returns**
196
197| Type| Description|
198| -- | -- |
199| int32_t | Result code defined in [IRNdkErrCode](capi-image-mdk-common-h.md#irndkerrcode):<br>**IMAGE_RESULT_SUCCESS**: The operation is successful.|
200
201**See also**
202
203[OH_ImagePacker_InitNative](#oh_imagepacker_initnative)
204