# ImageKnifeProExample
**Repository Path**: Keke_planet/image-knife-pro-example
## Basic Information
- **Project Name**: ImageKnifeProExample
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-04-21
- **Last Updated**: 2026-04-21
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
#
ImageKnifePro 源码引入示例
> 本示例使用源码引入ImageKnifePro,采用git subtree的方式,保留源库的commit记录
* 对源库的代码修改,直接正常commit
* 能够同步合入远端的代码
* 所有修改变更提交至主仓,其他人拉取该仓库后无需再次配置源imageknifepro仓库
## 目录结构
```
ImageKnifeProExample/
├── entry/ // 测试模块
│ ├── src/
│ │ ├── main/
│ │ │ ├── ets/ // demo页面
│ │ │ └── resource/
│ │ └── ohosTest/
│ ├── build-profile.json5
│ └── oh-package.json5 // 测试模块依赖描述
├── myimageknifepro/ // ImageKnifePro自定义封装模块
│ ├── src/
│ │ ├── imageknifepro/ // 源imageknifepro仓库添加目录
│ │ │ ├── entry/ // 源imageknifepro仓库测试模块
│ │ │ ├── library/ // 源imageknifepro仓库Har包提供模块
│ │ │ │ ├── include/ // 源imageknifepro仓库cpp头文件目录
│ │ │ │ ├── src/main/cpp
│ │ │ │ │ ├── CMakeLists.txt
│ │ │ │ │ ├── napi_init.cpp
│ │ │ │ │ └── thirdparty // 源imageknifepro仓库依赖的三方库
│ │ │ │ └── build-profile.json5 // 源imageknifepro仓库Har包模块编译配置文件
│ │ │ ├── README.md
│ │ │ ├── README_zh.md
│ │ │ └── README.OpenSource
│ │ ├── main/
│ │ │ ├── cpp/ // 自定义imageknifepro逻辑目录
│ │ │ │ ├── CMakeLists.txt
│ │ │ │ └── napi_init.cpp
│ │ │ └── Index.ets // 自定义封装模块Arkts接口导出
│ │ └── ohosTest/
│ ├── build-profile.json5 // 自定义封装模块依赖描述
│ └── oh-package.json5
├── build-profile.json5 // 工程级build-profile配置文件
└── README.md
```
## 以subtree方式引入ImageKnifePro
> 本示例imageknifepro仓库存放在其封装模块myimageknifepro下
这个章节介绍本示例仓库是如何以subtree方式引入ImageKnifePro的
### 添加远程仓库
在当前仓库根目录下执行
```shell
git remote add upstream https://gitcode.com/openharmony-sig/imageknifepro.git
git fetch upstream
```
### 子树添加imageknifepro
在当前仓库根目录下执行
```shell
git subtree add --prefix=myimageknifepro/src/imageknifepro upstream/master
```
注意这里不能使用`--squash`压缩,会丢失子树commit记录,使得后续无法从远端合入分支
### 添加源库submodules
> 子树添加后,源库的submodules并未自动拉取,而手动执行`git submodules --init`也无法拉取,因为目录路径不对。
> 而且拉取后submodules作为独立的仓库,并不能记录变更提交到主仓。
> 这里选择移除源库submodules,再手动添加
* 先清空`myimageknifepro/src/imageknifepro/.gitmodules`中的内容
* 然后移除源库thirdparty依赖以及git cache:
```shell
git rm --cached myimageknifepro/src/imageknifepro/library/src/main/cpp/thirdparty/base64 -r
git rm --cached myimageknifepro/src/imageknifepro/library/src/main/cpp/thirdparty/boundscheck -r
```
* 新建目录,单独拉取依赖库base64:`https://github.com/aklomp/base64.git`
* 新建目录,单独拉取依赖库boundscheck:`https://gitee.com/openharmony/third_party_bounds_checking_function.git`
* 将单独拉取的依赖库base64和boundscheck,删除隐藏文件`.git`,然后拷贝至当前仓库的`myimageknifepro/src/imageknifepro/library/src/main/cpp/thirdparty/`目录
* 保存变更至commit
### 设置模块间依赖
在工程级`build-profile.json5`(仓库根目录下),在配置文件中追加模块,指定源imageknifepro的模块位置:
```
"modules": [
{
"name": "library",
"srcPath": "./myimageknifepro/src/imageknifepro/library"
}
]
```
封装模块添加imageknifepro依赖,修改`myimageknifepro/oh-package.json5`:
```
"dependencies": {
"libmyimageknifepro.so": "file:./src/main/cpp/types/libmyimageknifepro",
"@ohos/imageknifepro": "file:./src/imageknifepro/library"
}
```
其他模块需要通过封装模块注入自定义逻辑,因此,其他模块需要直接依赖源imageknifepro,或封装模块。封装模块通常只需要初始化一次
本示例中,在entry模块的`oh-package.json5`进行类似的配置:
```
"dependencies": {
"@ohos/imageknifepro": "file:../myimageknifepro/src/imageknifepro/library",
"myimageknifepro": "file:../myimageknifepro"
}
```
### 设置Cmake
> 封装模块注入了自定义的imageknifepro逻辑,需要配置CMakeLists.txt
```
# 设置imageknifepro目录
set(IMAGEKNIFEPRO_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../imageknifepro/library/)
include_directories(${IMAGEKNIFEPRO_PATH}/src/main/cpp/include/) # 设置imageknifepro头文件搜索目录
# ... 其他配置
# 指定源imageknifepro的so目录
target_link_directories(myimageknifepro PUBLIC ${IMAGEKNIFEPRO_PATH}/build/default/intermediates/libs/default/${OHOS_ARCH})
target_link_libraries(myimageknifepro PUBLIC libace_napi.z.so libimageknifepro.so libpixelmap.so)
```
## 后续合入imageknifepro更新
> 本示例合入了另一个远端的分支,注意该分支以后可能已经合入imageknifepro上游仓库,本章节仅做示意
添加另一个远端
```shell
git remote add keke https://gitcode.com/openharmony-sig/imageknifepro.git
git fetch keke
```
将分支合并至subtree
```shell
git subtree merge --prefix=myimageknifepro/src/imageknifepro keke/common_crop
```
## 本仓库commit历史
> 子树模式引入imageknifepro,保留了源库的commit记录
