```c++
typedef struct {
int comps_num; // the number of components of the image.
int comps_prec; // number of bits per component per pixel
int img_width; // the image width
int img_height; // the image height
int title_width; // width of tile
int title_height; // height of title
int irreversible; // 1 : use the irreversible DWT 9-7
// 0 : use lossless compression (default)
int cblockw_init; // initial code block width, default to 64
int cblockh_init; // initial code block height, default to 64
int numresolution; // number of resolutions
int offsetx; // x component offset compared to the whole image
int offsety; // y component offset compared to the whole image
int is_rand; // Whether to generate data randomly
char file[256]; // output filename
} J2K_Info;
int OpenjpegCompress(const char *input_file, char *output_file) # 图片压缩成J2K格式
int openjpeg_create_j2k(J2K_Info *info) # 创建一张J2K格式图片
```
```c++
static int GetObjectPropetry(napi_env env, napi_value object, std::string key, int keyType, void *retValue) {
napi_value property = nullptr;
napi_value result = nullptr;
bool flag = false;
int ret = -1;
```js
export const openjpeg_compress: (srcName:string, desName:string) =>number;
interface openjpegOption{
comps_num:number // the number of components of the image.
comps_prec:number // number of bits per component per pixel
img_width:number // the image width
img_height:number // the image height
title_width:number // width of tile
title_height:number // height of title
irreversible:number // 1 : use the irreversible DWT 9-7,
// 0 : use lossless compression (default)
output_file:string // output filename
cblockw_init?:number // initial code block width, default to 64
cblockh_init?:number // initial code block height, default to 64
numresolution?:number // number of resolutions
offsetx?:number // x component offset compared to the whole image
offsety?:number // y component offset compared to the whole image
is_rand?:boolean // Whether to generate data randomly
}
export const openjpeg_create_j2k: (option:openjpegOption) => number
```
- 导入so文件
```ts
import testNapi from "libentry.so"
```
- JS应用调用接口
在ets工程中创建2个按钮,并通过按钮调用相关的接口,具体代码如下: