Compare commits

..

156 Commits

Author SHA1 Message Date
openharmony_ci a7fa5de2de
!405 ImageKnife降采样适配3.x
Merge pull request !405 from 田双明/master
2024-10-23 01:53:00 +00:00
田双明 346c704193
update entry/src/main/ets/pages/Index.ets.
Signed-off-by: 田双明 <tianshuangming@h-partners.com>
2024-10-23 01:12:36 +00:00
田双明 e857a41129 Merge branch 'master' of gitee.com:openharmony-tpc/ImageKnife into master
Signed-off-by: 田双明 <tianshuangming@h-partners.com>
2024-10-22 10:43:49 +00:00
openharmony_ci da4c159d44
!404 增加onLoadCancel回调的demo、增加设置图片颜色变换demo、增加从缓存获取图片格式大小的xts等
Merge pull request !404 from tyBrave/master
2024-10-21 01:28:42 +00:00
tsm 29e0df8d2b 降采样功demo文字国际化
Signed-off-by: tsm <tianshuangming@h-partners.com>
2024-10-18 18:16:42 +08:00
tsm 5fa004afc0 降采样功能
Signed-off-by: tsm <tianshuangming@h-partners.com>
2024-10-18 15:31:38 +08:00
tyBrave d82d85ea19 去掉多余的日志信息
Signed-off-by: tyBrave <tianyong21@h-partners.com>

TestCacheDataPage 文件添加版权头

Signed-off-by: tyBrave <tianyong21@h-partners.com>

资源国际化

Signed-off-by: tyBrave <tianyong21@h-partners.com>

add TIPS text dec

Signed-off-by: tyBrave <tianyong21@h-partners.com>

update code because of checkcode

Signed-off-by: tyBrave <tianyong21@h-partners.com>

update code because of use image url

Signed-off-by: tyBrave <tianyong21@h-partners.com>
2024-10-17 17:39:50 +08:00
tyBrave 8e55d336f9 修改获取缓存中的图片格式大小的单元测试
Signed-off-by: tyBrave <tianyong21@h-partners.com>
2024-10-16 17:17:02 +08:00
tyBrave e31c592ee4 修改onLoadCancel回调demo及其缓存中获取图片的格式大小信息
Signed-off-by: tyBrave <tianyong21@h-partners.com>
2024-10-16 15:56:42 +08:00
tyBrave 1027fc0304 add xts test get size and format in image of callback
Signed-off-by: tyBrave <tianyong21@h-partners.com>
2024-10-16 10:57:36 +08:00
tyBrave ec651e91df add test cancel callback demo
Signed-off-by: tyBrave <tianyong21@h-partners.com>
2024-10-16 10:56:06 +08:00
tyBrave 7b9da8d9fa add change color of image in lib
Signed-off-by: tyBrave <tianyong21@h-partners.com>
2024-10-16 10:40:22 +08:00
tyBrave 2a81312ed5 add get cache data
Signed-off-by: tyBrave <tianyong21@h-partners.com>
2024-10-12 09:57:11 +08:00
openharmony_ci 78770a430c
!398 中文图片链接替换
Merge pull request !398 from zgf/master
2024-10-10 01:24:31 +00:00
zgf 2201fec90c 中文图片链接替换
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-10-09 15:36:07 +08:00
openharmony_ci f7cef581b1
!388 适配国际化
Merge pull request !388 from hexagon1337/master
2024-09-25 03:40:24 +00:00
hexagon1337 ddb8fc89be 修改README_zh屏蔽词
Signed-off-by: hexagon1337 <liuyaoming3@h-partners.com>
2024-09-25 11:03:44 +08:00
hexagon1337 858e28c3a2 补充imagetransformation和removecache页面的国际化
Signed-off-by: hexagon1337 <liuyaoming3@h-partners.com>
2024-09-25 10:34:33 +08:00
hexagon1337 565938c98a 补充imagetransformation和removecache页面的国际化
Signed-off-by: hexagon1337 <liuyaoming3@h-partners.com>
2024-09-23 12:14:04 +08:00
hexagon1337 f1008e869e 适配国际化
Signed-off-by: hexagon1337 <liuyaoming3@h-partners.com>
2024-09-21 18:19:06 +08:00
openharmony_ci afde885ae1
!385 调整内部包的结构
Merge pull request !385 from Madi/master
2024-09-06 09:04:17 +00:00
Madixin 9f98c174f2 调整内部包的结构
Signed-off-by: Madixin <madixin@huawei.com>
2024-09-06 16:39:42 +08:00
openharmony_ci b491bc8dae
!384 重构代码:抽取ImageKnifeDispatcher子线程requestJob相关代码到ImageKnifeLoader中,降低函数复杂度
Merge pull request !384 from Madi/master
2024-09-06 08:19:22 +00:00
Madixin 6cbe5eadc5 重构代码:抽取ImageKnifeDispatcher子线程requestJob相关代码到ImageKnifeLoader中,降低函数复杂度
Signed-off-by: Madixin <madixin@huawei.com>
2024-09-06 15:15:35 +08:00
zgf 0dd26b9e75 Revert "降采样"
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-09-06 11:05:46 +08:00
openharmony_ci 233b24032e
!382 修改网络请求超时设置
Merge pull request !382 from zgf/master
2024-09-05 10:35:52 +00:00
zgf d78ba39efe 修改网络请求超时设置
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-09-05 18:08:43 +08:00
zgf dcdc17f51f 修改网络请求超时设置
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-09-05 18:04:21 +08:00
openharmony_ci 483803a302
!380 修改file格式图片同步close和PixelMap默认不可编辑
Merge pull request !380 from zgf/master
2024-09-02 08:38:03 +00:00
zgf 2cbce5790b 修改file格式图片同步close和PixelMap默认不可编辑
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-09-02 15:58:32 +08:00
openharmony_ci f9e83786a8
!379 imageKnife降采样
Merge pull request !379 from 田双明/master
2024-09-02 07:43:33 +00:00
tsm f415bb7aa1 降采样
Signed-off-by: tsm <tianshuangming@h-partners.com>
2024-09-02 11:44:53 +08:00
openharmony_ci 55fcfe6021
!375 ImageknifeComponents代码整理
Merge pull request !375 from Madi/master
2024-08-30 06:26:33 +00:00
Madixin 587d35f085 优化整理imageknifecomponent代码
Signed-off-by: Madixin <madixin@huawei.com>
2024-08-30 11:56:11 +08:00
openharmony_ci b3114dd47b
!371 新增Task任务报错10200006样例
Merge pull request !371 from zgf/master
2024-08-28 09:26:58 +00:00
zgf 0c8a777c82 新增Task任务报错10200006样例
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-28 17:00:43 +08:00
zgf ddbff75a7d 新增Task任务报错10200006样例
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-28 16:27:47 +08:00
zgf 2911708267 子线程本地Resource参数类型转换成number
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-27 11:30:08 +00:00
zgf 7252a2fe05 子线程本地Resource参数类型转换成number
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-27 16:48:48 +08:00
Madixin 47c178fe1f 修改使用hilog记录日志,默认打开debug级别的日志,增加可维侧性
Signed-off-by: Madixin <madixin@huawei.com>
2024-08-27 16:37:47 +08:00
openharmony_ci 6612dea1d5
!368 修改webp图片区分动静图和错误图加载完未发起排队队列中的请求
Merge pull request !368 from zgf/master
2024-08-23 09:45:04 +00:00
zgf fae5b3c7fd 修改webp图片区分动静图和错误图加载完未发起排队队列中的请求
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-23 17:28:50 +08:00
Madi ad18fe60b2
!366 修复宽高不等svg图片显示有毛边
Merge pull request !366 from zgf/master
2024-08-19 03:47:42 +00:00
zgf 906337cc62 修复宽高不等svg图片显示有毛边
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-19 11:01:32 +08:00
openharmony_ci fa59e2b9ac
!365 修改README待实现特性
Merge pull request !365 from zgf/master
2024-08-15 06:56:52 +00:00
zgf bebbc865f7 修改README待实现特性
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-15 14:44:38 +08:00
zgf 48b425109a 控制动图组件新增事件和文件缓存数量最大值修改
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-14 17:29:58 +08:00
openharmony_ci bea89c5c77
!361 新增动画显示首帧和第一帧样例
Merge pull request !361 from zgf/master
2024-08-14 08:18:04 +00:00
zgf 4898145979 新增动画显示首帧和第一帧样例
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-09 16:07:33 +08:00
openharmony_ci dd0c64fb91
!359 修复xts报错:ImageKnifeOption用法变更
Merge pull request !359 from zgf/master
2024-08-07 10:18:13 +00:00
zgf 5c1b0578b6 修复xts报错:ImageKnifeOption用法变更
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-07 18:05:26 +08:00
zgf cdfb4fafa9 修复xts报错:ImageKnifeOption用法变更
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-07 17:42:07 +08:00
openharmony_ci 370cc03b96
!357 适配ComponentV2装饰器
Merge pull request !357 from zgf/master
2024-08-06 07:29:26 +00:00
zgf 1b05a2aa2d ComponentV2装饰器适配
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-06 11:37:43 +08:00
zgf d7a14b8833 修复webp静态图无法设置图形变换
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-05 10:07:37 +08:00
zgf 69f951b290 修复动图控制组件初始值失效、网络请求成功code以及文件缓存可选初始化
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-08-02 16:25:41 +08:00
wangyingjun01 f497f32c48 ImageKnife3.x分支合并到master分支
Signed-off-by: wangyingjun01 <wangyingjun5@h-partners.com>
2024-07-31 11:41:01 +08:00
wangyingjun01 7fac49e442 ImageKnife3.x分支合并到master分支
Signed-off-by: wangyingjun01 <wangyingjun5@h-partners.com>
2024-07-31 11:23:37 +08:00
wangyingjun01 45b1fbc591 ImageKnife3.x分支合并到master分支
Signed-off-by: wangyingjun01 <wangyingjun5@h-partners.com>
2024-07-31 11:06:41 +08:00
wangyingjun01 7d39ff5129 Merge remote-tracking branch 'origin/3.x'
# Conflicts:
#	CHANGELOG.md
#	OAT.xml
#	README.md
#	build-profile.json5
#	entry/oh-package.json5
#	entry/src/main/ets/entryability/EntryAbility.ets
#	entry/src/main/ets/pages/UserPage.ets
#	entry/src/main/ets/pages/dataShareUriLoadPage.ets
#	entry/src/main/ets/pages/imageknifeTestCaseIndex.ets
#	entry/src/main/ets/pages/index.ets
#	entry/src/main/ets/pages/testImageKnifeHttpRequestHeader.ets
#	entry/src/main/ets/pages/testImageKnifeOptionChangedPage5.ets
#	entry/src/main/ets/pages/testManyNetImageLoadWithPage2.ets
#	entry/src/main/module.json5
#	entry/src/main/resources/base/element/string.json
#	entry/src/main/resources/base/profile/main_pages.json
#	entry/src/ohosTest/ets/test/DefaultJobQueueTest.test.ets
#	entry/src/ohosTest/ets/test/List.test.ets
#	entry/src/ohosTest/ets/test/diskLruCache.test.ets
#	entry/src/ohosTest/ets/test/imageknife.test.ets
#	entry/src/ohosTest/ets/test/requestoption.test.ets
#	entry/src/ohosTest/module.json5
#	gpu_transform/CHANGELOG.md
#	gpu_transform/oh-package.json5
#	library/index.ets
#	library/oh-package.json5
#	library/src/main/ets/SendableData.ets
#	library/src/main/ets/components/cache/DiskCacheEntry.ets
#	library/src/main/ets/components/cache/DiskLruCache.ets
#	library/src/main/ets/components/cache/FileUtils.ets
#	library/src/main/ets/components/cache/LruCache.ets
#	library/src/main/ets/components/imageknife/ImageKnife.ets
#	library/src/main/ets/components/imageknife/ImageKnifeComponent.ets
#	library/src/main/ets/components/imageknife/ImageKnifeData.ets
#	library/src/main/ets/components/imageknife/ImageKnifeDrawFactory.ets
#	library/src/main/ets/components/imageknife/ImageKnifeOption.ets
#	library/src/main/ets/components/imageknife/RequestOption.ets
#	library/src/main/ets/components/imageknife/TaskParams.ets
#	library/src/main/ets/components/imageknife/constants/Constants.ets
#	library/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets
#	library/src/main/ets/components/imageknife/holder/PlaceHolderManager.ets
#	library/src/main/ets/components/imageknife/holder/RetryHolderManager.ets
#	library/src/main/ets/components/imageknife/interface/IParseImage.ets
#	library/src/main/ets/components/imageknife/networkmanage/DownloadClient.ets
#	library/src/main/ets/components/imageknife/networkmanage/HttpDownloadClient.ets
#	library/src/main/ets/components/imageknife/networkmanage/IDataFetch.ets
#	library/src/main/ets/components/imageknife/networkmanage/LoadDataShareFileClient.ets
#	library/src/main/ets/components/imageknife/networkmanage/LoadLocalFileClient.ets
#	library/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets
#	library/src/main/ets/components/imageknife/requestmanage/MemoryCacheProxy.ets
#	library/src/main/ets/components/imageknife/requestmanage/RequestManager.ets
#	library/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets
#	library/src/main/ets/components/imageknife/transform/TransformUtils.ets
#	library/src/main/ets/components/imageknife/utils/ParseImageUtil.ets
#	library/src/main/ets/components/imageknife/utils/gif/GIFFrame.ts
#	library/src/main/ets/components/imageknife/utils/gif/GIFParseImpl.ets
#	library/src/main/ets/components/imageknife/utils/gif/IParseGif.ets
#	library/src/main/ets/components/imageknife/utils/svg/SVGParseImpl.ets
#	library/src/main/ets/downsampling/BaseDownsampling.ets
#	library/src/main/ets/downsampling/DownsampleStartegy.ets
#	library/src/main/ets/downsampling/Downsampler.ets
#	library/src/main/ets/networkmanage/CustomDataFetchClient.ets
#	library/src/main/ets/networkmanage/DataFetchResult.ets
#	library/src/main/ets/networkmanage/RequestData.ets
#	library/src/main/ets/utils/CalculatePixelUtils.ets
#	library/src/main/ets/utils/DefaultJobQueue.ets
#	library/src/main/ets/utils/IJobQueue.ets
#	library/src/main/ets/utils/MResource.ets
#	library/src/main/ets/utils/base/AsyncLock.ts
#	oh-package.json5
#	sharedlibrary/src/main/ets/Index.ets
#	sharedlibrary/src/main/ets/pages/Index.ets
#	sharedlibrary/src/test/List.test.ets
2024-07-31 11:02:46 +08:00
openharmony_ci 8f41c6d13e
!345 去除READ_IMAGEVIDEO和WRITE_IMAGEVIDEO权限以及修复部分heif图无法解码
Merge pull request !345 from zgf/master
2024-07-24 02:36:16 +00:00
zgf 7101a26267 去除READ_IMAGEVIDEO和WRITE_IMAGEVIDEO权限以及修复部分heif图无法解码
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-07-24 10:01:12 +08:00
zgf 1dee5f345b 去除READ_IMAGEVIDEO和WRITE_IMAGEVIDEO权限以及修复部分heif图无法解码
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-07-23 16:34:16 +08:00
zgf d2bd8f75fc 修改下采样和hsp本地图样例
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-07-22 14:41:15 +08:00
openharmony_ci 659d28dd37
!340 加载优先级Priority类型改为taskpool.Priority类型
Merge pull request !340 from zgf/master
2024-07-18 06:18:40 +00:00
zgf 136c3e509a 加载优先级Priority类型改为taskpool.Priority类型
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-07-18 10:55:44 +08:00
chongtiantian e48600fe7f 修改uuid的生成方式,使用资源loadSrc,宽高以及转换效果的拼接字符串作为入参,修复同资源图形转换错乱的问题。
Signed-off-by: chongtiantian <chongtiantian1@h-partners.com>
2024-07-01 16:07:57 +08:00
zgf db1ccdc604 修复file://格式图片无法显示以及媒体展示图片样例改用photoAccessHelper接口获取本地图片资源
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-06-27 06:44:44 +00:00
openharmony_ci c51e0eca77
!318 X86模拟器配置
Merge pull request !318 from yaofangyong/master
2024-06-27 06:34:28 +00:00
yaofangyong d873733517 x86
Signed-off-by: yaofangyong <2385605052@qq.com>
2024-06-25 19:34:37 +08:00
Madi a3026e13e8
!312 修改xts用例setCache和getMapCache
Merge pull request !312 from zgf/master
2024-06-19 13:58:26 +00:00
zgf 334b042086 修改xts用例setCache和getMapCache
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-06-19 21:49:08 +08:00
Madi 7c0fc08d9d
!311 增加gif图duration的默认值,以及默认播放次数
Merge pull request !311 from zgf/master
2024-06-19 11:37:42 +00:00
zgf f171b64e95 增加gif图duration的默认值,以及默认播放次数
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-06-19 19:24:51 +08:00
zgf 549658e321 修改CHANGELOG
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-06-19 19:00:09 +08:00
zgf 7b4f496150 1.修复复用场景下从内存获取图片后又清空了画布导致图片不显示,
2.svg解码单位改为px
3.获取组件宽高改用onSizeChange
4.修复复用占位图不显示

Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-06-14 15:03:00 +08:00
Madi d4a87f0c5e
!304 修复多线程图片加载出现空白问题
Merge pull request !304 from baofeng/master
2024-06-13 06:20:16 +00:00
baofeng f7ce1945b8 修复多线程图片加载出现空白问题
Signed-off-by: baofeng <baofeng6@h-partners.com>
2024-06-12 18:37:14 +08:00
openharmony_ci ee980fe094
!302 imageKnife降采样案例修改
Merge pull request !302 from 田双明/master
2024-06-11 08:20:16 +00:00
tsm fe80ce7a34 降采样案例修改
Signed-off-by: tsm <2418639820@qq.com>
2024-06-11 15:19:54 +08:00
sunao d6e3ebc253 修改门禁编译问题 修改点如下:修改src/main/cpp/boundscheck/CMakeLists.txt文件中的内容,修改src/main/cpp/util/DebugLog.h文件中hilog的大小写
Signed-off-by: sunao <sunao19@h-partners.com>
2024-06-07 17:18:10 +08:00
openharmony_ci 804049b36b
!292 修复preLoad接口失效
Merge pull request !292 from zgf/master
2024-06-03 07:52:15 +00:00
zgf bafd1a568f 修复preLoad接口失效
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-06-03 15:02:43 +08:00
openharmony_ci f7bb2f1999
!287 ImageKnife提供图片加载成功/失败的事件README补充
Merge pull request !287 from 任伟x/master
2024-05-27 09:31:50 +00:00
任伟x b777d40426 ImageKnife提供图片加载成功失败的事件README补充
Signed-off-by: 任伟x <renwei79@h-partners.com>
2024-05-27 16:58:59 +08:00
openharmony_ci 0d27e7a8cc
!281 修改readme文档
Merge pull request !281 from zhanghuan633/master
2024-05-24 08:43:48 +00:00
张欢 ce8b3cbb7a 修改readme文档
Signed-off-by: 张欢 <zhanghuan165@h-partners.com>
2024-05-24 16:19:49 +08:00
openharmony_ci 668bf251fd
!276 ImageKnife提供清理缓存能力
Merge pull request !276 from 任伟x/master
2024-05-23 06:56:58 +00:00
任伟x ee6e0acef6 ImageKnife提供清理缓存能力
Signed-off-by: 任伟x <renwei79@h-partners.com>
2024-05-22 17:28:30 +08:00
openharmony_ci 3ecc586559
!268 ImageKnife支持多种组合变换
Merge pull request !268 from zhanghanyong/master
2024-05-22 09:02:14 +00:00
zhang_hanyong 1e94a03d5b 支持多种组合变换
Signed-off-by: zhang_hanyong <zhang_hanyong@h-partners.com>
2024-05-21 11:02:53 +08:00
张欢 6d43923279 修复懒加载在多次点击出现卡死的问题
Signed-off-by: 张欢 <zhanghuan165@h-partners.com>
2024-05-20 15:25:19 +08:00
openharmony_ci 83e76dcc08
!260 ImageKnife提供图片加载成功/失败的事件
Merge pull request !260 from 任伟x/master
2024-05-16 02:15:01 +00:00
任伟x 275ee6bc0a ImageKnife提供图片加载成功失败的事件
Signed-off-by: 任伟x <renwei79@h-partners.com>
2024-05-15 16:55:29 +08:00
zgf 39f97e0a41 修复错误图绘制完后变成占位图
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-05-11 10:01:09 +08:00
openharmony_ci b74f6e68ec
!253 更新版本信息
Merge pull request !253 from 田双明/master
2024-05-10 01:18:28 +00:00
sijainguo 2731a7f8cc 版本信息修改
Signed-off-by: sijainguo <sijianguo5@h-partners.com>
2024-05-09 11:27:55 +08:00
openharmony_ci 8fbc60f907
!202 使用安全函数memset_s替代memset,memcpy_s替代memcpy
Merge pull request !202 from 刘海康/master
2024-05-08 00:35:51 +00:00
openharmony_ci 937f448fb7
!247 imageKnife降采样
Merge pull request !247 from 田双明/master
2024-05-07 03:48:56 +00:00
tsm d6a3f2df0e imageKnife 下采样
Signed-off-by: tsm <2418639820@qq.com>
2024-05-07 11:01:14 +08:00
openharmony_ci 49502f1143
!240 修改header图的存储标志位
Merge pull request !240 from taxuexunji/master
2024-05-06 03:02:10 +00:00
2206069183@qq.com 4f549b2f81 修改header图的存储标志位
Signed-off-by: 2206069183@qq.com <2206069183@qq.com>
2024-05-06 10:32:19 +08:00
openharmony_ci a27ca5b4c7
!234 ImageKnife组件修改配置字段srcEntrance替换为srcEntry
Merge pull request !234 from xiagengwen/master
2024-05-05 02:38:12 +00:00
Madi ac409d4ac9
!237 修复通过磁盘链接加载图片无法显示
Merge pull request !237 from zgf/master
2024-05-04 10:35:13 +00:00
Madi 98145712fa
!235 修复占位图、错误图、重试图从内存获取之后进入子线程导致内存泄露
Merge pull request !235 from zgf/master
2024-05-04 10:34:42 +00:00
zgf 08ba6360c7 修复通过磁盘链接加载图片无法显示
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-05-04 17:53:55 +08:00
zgf a6bbe8341a 修复占位图、错误图、重试图从内存获取之后进入子线程导致内存泄露
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-05-04 17:09:21 +08:00
xiagengwen ceb5fe7010 ImageKnife组件修改配置字段srcEntrance替换为srcEntry
Signed-off-by: xiagengwen <xiagengwen1@h-partners.com>
2024-05-04 15:22:45 +08:00
openharmony_ci 4ee4760aed
!229 ImageKnife控制可视化区域图片
Merge pull request !229 from 17792399693/master
2024-04-30 02:50:06 +00:00
chongtiantian f54b5045c7 ImageKnife控制可视化区域图片
Signed-off-by: chongtiantian <chongtiantian1@h-partners.com>
2024-04-29 17:58:07 +08:00
openharmony_ci d5faaf74d2
!226 ImageKnife支持heic图片修改demo
Merge pull request !226 from taxuexunji/master
2024-04-29 06:59:54 +00:00
2206069183@qq.com 240a2658a7 修改heic图片展示demo
Signed-off-by: 2206069183@qq.com <2206069183@qq.com>
2024-04-29 10:19:22 +08:00
openharmony_ci bb57dc0f51
!223 【ImageKnife】加载图片支持自定义网络栈补充XTS用例以及优化按钮重复点击问题
Merge pull request !223 from zhanghanyong/master
2024-04-29 01:41:40 +00:00
zhang_hanyong b185bf1f18 ImageKnife加载图片支持自定义网络栈补充XTS用例以及优化按钮重复点击问题
Signed-off-by: zhang_hanyong <zhang_hanyong@h-partners.com>
2024-04-28 18:12:06 +08:00
liuhaikang 46b75226cf 使用安全函数memset_s替代memset,memcpy_s替代memcpy
Signed-off-by: liuhaikang <liuhaikang@huawei-partners.com>
2024-04-28 10:21:54 +08:00
openharmony_ci 97a5ca1ec2
!221 新增自定义key获取已缓存的图片单元测试
Merge pull request !221 from 任伟x/master
2024-04-25 02:10:08 +00:00
任伟x 68257fb666 Merge branch 'master' of gitee.com:openharmony-tpc/ImageKnife into master
Signed-off-by: 任伟x <renwei79@h-partners.com>
2024-04-24 08:17:28 +00:00
任伟x 06ab9131ed ImageKnife支持根据自定义key获取已缓存的图片-新增xts
Signed-off-by: 任伟x <renwei79@h-partners.com>
2024-04-24 16:05:48 +08:00
openharmony_ci befcd414ac
!219 ImageKnife控制重要图片请求加载优先级
Merge pull request !219 from 17792399693/master
2024-04-24 06:20:29 +00:00
chongtiantian 87f3dab4fa ImageKnife控制重要图片请求加载优先级
Signed-off-by: chongtiantian <chongtiantian1@h-partners.com>
2024-04-24 10:05:23 +08:00
openharmony_ci 32b29801bd
!217 适配复用场景触发懒加载onDataReloaded
Merge pull request !217 from zgf/master
2024-04-24 01:48:21 +00:00
zenggaofeng 9bc31bb138 适配复用场景触发懒加载onDataReloaded
Signed-off-by: zenggaofeng <zenggaofeng2@h-partners.com>
2024-04-23 20:32:37 +08:00
chenchen2019710 ec861fb89f 修改ImageKnife跳过网络,点击默认,图片没有传入宽高,无显示bug
Signed-off-by: chenchen2019710 <1173940354@qq.com>
2024-04-23 17:48:45 +08:00
openharmony_ci 5fdc066846
!215 【ImageKnife】加载图片支持自定义网络栈和图片加载组件
Merge pull request !215 from zhanghanyong/master
2024-04-23 08:26:42 +00:00
zhang_hanyong 9ff235a856 ImageKnife加载图片支持自定义网络栈和图片加载组件
Signed-off-by: zhang_hanyong <zhang_hanyong@h-partners.com>
2024-04-23 16:00:20 +08:00
openharmony_ci 906bfe55f1
!211 ImageKnife支持根据自定义key获取已缓存的图片
Merge pull request !211 from 任伟x/master
2024-04-23 03:45:27 +00:00
任伟x 6ae9982ec6 ImageKnife支持根据自定义key获取已缓存的图片
Signed-off-by: 任伟x <renwei79@h-partners.com>
2024-04-23 10:37:44 +08:00
openharmony_ci 83075cc204
!204 【ImageKnife】支持加载的网络gif图设置圆角
Merge pull request !204 from zhanghanyong/master
2024-04-20 07:03:51 +00:00
zhanghanyong 160d08d336 drawLifeCycle支持gif图
Signed-off-by: zhanghanyong <zhanghanyong@h-partners.com>
2024-04-19 17:35:00 +08:00
openharmony_ci 3e4f204027
!195 imageKnife支持heic图片(修改heic的demo,独立页面)
Merge pull request !195 from 袁莉/master
2024-04-19 09:02:31 +00:00
18829029633 43daaec752 imageKnife支持heic展示demo页面独立展示
Signed-off-by: 18829029633 <18829029633@163.com>
2024-04-19 16:09:25 +08:00
openharmony_ci 90ff9edf1d
!200 修改全局请求头覆盖request请求头
Merge pull request !200 from taxuexunji/master
2024-04-19 07:24:49 +00:00
2206069183@qq.com d4b537bd53 修改全局请求头覆盖request请求头
Signed-off-by: 2206069183@qq.com <2206069183@qq.com>
2024-04-19 14:50:32 +08:00
openharmony_ci f20aed06a5
!162 修复自定义DataFetch接口不生效问题
Merge pull request !162 from baofeng/master
2024-04-19 03:41:34 +00:00
baofeng f84b793eca [Issues: #I9DWXC]修复自定义DataFetch接口不生效问题
Signed-off-by: baofeng <baofeng6@h-partners.com>
2024-04-19 10:44:38 +08:00
zenggaofeng 95a2526408 OpenSource、OAT版权头修改
Signed-off-by: zenggaofeng <zenggaofeng2@h-partners.com>
2024-04-18 01:57:47 +00:00
Madi 2c4257f3f6
!197 gpu_transform安全编译开启Strip和Ftrapv
Merge pull request !197 from zhanghuan633/master
2024-04-17 12:11:42 +00:00
张欢 2fad9a284d gpu_transform安全编译开启Strip和Ftrapv
Signed-off-by: 张欢 <zhanghuan165@h-partners.com>
2024-04-17 17:48:04 +08:00
openharmony_ci a2a8700eb4
!194 新增gif图暂停播放恢复播放能力
Merge pull request !194 from zhanghanyong/master
2024-04-17 07:56:34 +00:00
zhang_hanyong db71776e62 新增gif图暂停播放恢复播放能力
Signed-off-by: zhang_hanyong <zhanghanyong@h-partners.com>
2024-04-16 19:38:16 +08:00
openharmony_ci ab7dd919f3
!182 imageKnife支持heic图片
Merge pull request !182 from 袁莉/master
2024-04-12 02:45:04 +00:00
18829029633 0a4063b953 imageKnife支持heic图片展示 2024-04-11 18:00:27 +08:00
Madi 1996127cb6
!181 webp格式图片,实现首页轮盘跳动动画
Merge pull request !181 from LuQian-KUN/master
2024-04-11 09:26:52 +00:00
LuQian-KUN 997f5faf0d webp格式图片,实现首页轮盘跳动动画
Signed-off-by: 'LuQian-KUN' <gaopengcheng11@h-partners.com>
2024-04-11 15:49:39 +08:00
openharmony_ci 80550c27a6
!177 修改ImageKnife跳过网络,从内存中获取图片 cacheType参数未使用bug
Merge pull request !177 from 面条侠/master
2024-04-10 09:28:53 +00:00
‘面条侠’ 0a3aac2b77 修改ImageKnife跳过网络,从内存中获取图片 cacheType参数未使用bug
Signed-off-by: ‘面条侠’ <‘wangxinxin51@h-partners.com’>
2024-04-10 17:01:17 +08:00
‘面条侠’ db4e10c580 修改ImageKnife跳过网络,从内存中获取图片 cacheType参数未使用bug
Signed-off-by: ‘面条侠’ <‘wangxinxin51@h-partners.com’>
2024-04-10 16:28:30 +08:00
‘面条侠’ b5aef4c48c 修改ImageKnife跳过网络,从内存中获取图片 cacheType参数未使用bug
Signed-off-by: ‘面条侠’ <‘wangxinxin51@h-partners.com’>
2024-04-10 16:22:07 +08:00
openharmony_ci 99e251c6bd
!172 排查性能优化点uuid,定时器以及磁盘读写
Merge pull request !172 from zgf/master
2024-04-09 11:12:41 +00:00
openharmony_ci b7eae6eefb
!163 新增gif播放次数
Merge pull request !163 from zgf/master
2024-04-09 06:57:49 +00:00
zenggaofeng ccb69591df 排查性能优化点uuid,定时器以及磁盘读写
Signed-off-by: zenggaofeng <zenggaofeng2@h-partners.com>
2024-04-09 14:28:27 +08:00
openharmony_ci 15b77e25c4
!169 跳过网络,从内存中取图片,接口说明文档
Merge pull request !169 from 面条侠/master
2024-04-08 06:36:33 +00:00
‘面条侠’ 0c239e1118 跳过网络,从内存中取图片,接口说明文档
Signed-off-by: ‘面条侠’ <‘wangxinxin51@h-partners.com’>
2024-04-08 10:59:22 +08:00
面条侠 b64661b9f9
update README.md.
Signed-off-by: 面条侠 <wangxinxin51@h-partners.com>
2024-04-08 02:57:50 +00:00
zenggaofeng f57fa66fab 新增gif播放次数
Signed-off-by: zenggaofeng <zenggaofeng2@h-partners.com>
2024-04-07 10:44:47 +08:00
longfeng 4d5728dc3a 支持x86编译
Signed-off-by: longfeng <longfeng20@huawei.com>
2024-04-01 16:18:47 +08:00
89 changed files with 2522 additions and 3429 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "gpu_transform/src/main/cpp/boundscheck/third_party_bounds_checking_function"]
path = gpu_transform/src/main/cpp/boundscheck/third_party_bounds_checking_function
url = https://gitee.com/openharmony/third_party_bounds_checking_function.git

View File

@ -1,20 +1,27 @@
## 3.0.2-rc.2 ## 3.1.1-rc.1
- ImageKnifeAnimatorComponent新增开始、结束、暂停的回调事件 - Photo reduction sampling
- 文件缓存数量负数和超过INT最大值时默认为INT最大值 ## 3.1.1-rc.0
- 修复宽高不等svg图片显示有毛边 - 重构代码抽取ImageKnifeDispatcher子线程requestJob相关代码到ImageKnifeLoader中降低函数复杂度
## 3.1.0
- 部分静态webp图片有delay属性导致识别成动图,改用getFrameCount识别 - 部分静态webp图片有delay属性导致识别成动图,改用getFrameCount识别
- 修复加载错误图后未去请求排队队列中的请求 - 修复加载错误图后未去请求排队队列中的请求
- 子线程本地Resource参数类型转换成number - 子线程本地Resource参数类型转换成number
- 修改使用hilog记录日志默认打开debug级别的日志 - 修改使用hilog记录日志默认打开debug级别的日志
- file格式图片fd同步close
- 解码pixelMap默认不可编辑图形变化可编辑 - 解码pixelMap默认不可编辑图形变化可编辑
- 修改网络请求超时设置 - 修改网络请求超时设置
- 重构代码抽取ImageKnifeDispatcher子线程requestJob相关代码到ImageKnifeLoader中降低函数复杂度
## 3.0.2-rc.1 ## 3.1.0-rc.2
- release打包关闭混淆 - 修复宽高不等svg图片显示有毛边
## 3.0.2-rc.0 ## 3.1.0-rc.1
- FileUtil.readFile接口和file格式图片同步关闭fd - ImageKnifeAnimatorComponent新增开始、结束、暂停的回调事件
- 文件缓存数量负数和超过INT最大值时默认为INT最大值
## 3.1.0-rc.0
- ComponentV2装饰器适配
- imageKnifeOption={...}用法改为new ImageKnifeOption({...})
- animatorOption={...}用法改为new AnimatorOption({...})
## 3.0.1 ## 3.0.1
- 修复animatorOption属性设置初始化值失效 - 修复animatorOption属性设置初始化值失效

17
OAT.xml
View File

@ -1,4 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
-->
<configuration> <configuration>
<oatconfig> <oatconfig>
<filefilterlist> <filefilterlist>

View File

@ -2,9 +2,9 @@
{ {
"Name": "glide", "Name": "glide",
"License": "Apache License 2.0", "License": "Apache License 2.0",
"License File": "https://github.com/bumptech/glide/blob/master/LICENSE", "License File": "LICENSE",
"Version Number": "4.13.1", "Version Number": "4.13.1",
"Owner" : "bumptech", "Owner" : "xiafeng@huawei.com",
"Upstream URL": "https://github.com/bumptech/glide", "Upstream URL": "https://github.com/bumptech/glide",
"Description": "An image loading and caching library focused on smooth scrolling" "Description": "An image loading and caching library focused on smooth scrolling"
}, },
@ -12,9 +12,9 @@
{ {
"Name": "glide-transformations", "Name": "glide-transformations",
"License": "Apache License 2.0", "License": "Apache License 2.0",
"License File": "https://github.com/wasabeef/glide-transformations/blob/main/LICENSE", "License File": "LICENSE",
"Version Number": "4.3.0", "Version Number": "4.3.0",
"Owner" : "wasabeef", "Owner" : "xiafeng@huawei.com",
"Upstream URL": "https://github.com/wasabeef/glide-transformations", "Upstream URL": "https://github.com/wasabeef/glide-transformations",
"Description": " An transformation library providing a variety of image transformations for Glide. " "Description": " An transformation library providing a variety of image transformations for Glide. "
}, },
@ -22,9 +22,9 @@
{ {
"Name": "fresco", "Name": "fresco",
"License": "MIT License", "License": "MIT License",
"License File": "https://github.com/facebook/fresco/blob/main/LICENSE", "License File": "LICENSE",
"Version Number": "2.6.0", "Version Number": "2.6.0",
"Owner" : "facebook", "Owner" : "xiafeng@huawei.com",
"Upstream URL": "https://github.com/facebook/fresco", "Upstream URL": "https://github.com/facebook/fresco",
"Description": " An library for managing images and the memory they use. " "Description": " An library for managing images and the memory they use. "
}, },
@ -32,9 +32,9 @@
{ {
"Name": "UPNG.js", "Name": "UPNG.js",
"License": "MIT License", "License": "MIT License",
"License File": "https://github.com/photopea/UPNG.js/blob/master/LICENSE", "License File": "LICENSE",
"Version Number": "1.0.0", "Version Number": "1.0.0",
"Owner" : "photopea", "Owner" : "xiafeng@huawei.com",
"Upstream URL": "https://github.com/photopea/UPNG.js", "Upstream URL": "https://github.com/photopea/UPNG.js",
"Description": " Fast and advanced PNG (APNG) decoder and encoder (lossy / lossless) " "Description": " Fast and advanced PNG (APNG) decoder and encoder (lossy / lossless) "
}, },
@ -42,9 +42,9 @@
{ {
"Name": "Luban", "Name": "Luban",
"License": "Apache License 2.0", "License": "Apache License 2.0",
"License File": "https://github.com/Curzibn/Luban/blob/master/LICENSE", "License File": "LICENSE",
"Version Number": "1.1.8", "Version Number": "1.1.8",
"Owner" : " Curzibn", "Owner" : " xiafeng@huawei.com",
"Upstream URL": "https://github.com/Curzibn/Luban", "Upstream URL": "https://github.com/Curzibn/Luban",
"Description": " Luban(鲁班)—Image compression with efficiency very close to WeChat Moments/可能是最接近微信朋友圈的图片压缩算法 " "Description": " Luban(鲁班)—Image compression with efficiency very close to WeChat Moments/可能是最接近微信朋友圈的图片压缩算法 "
}, },
@ -54,16 +54,16 @@
"License": "Apache License 2.0", "License": "Apache License 2.0",
"License File": "https://github.com/Yalantis/uCrop/blob/develop/README.md", "License File": "https://github.com/Yalantis/uCrop/blob/develop/README.md",
"Version Number": "2.2.8", "Version Number": "2.2.8",
"Owner" : " Yalantis", "Owner" : " xiafeng@huawei.com",
"Upstream URL": "https://github.com/Yalantis/uCrop", "Upstream URL": "https://github.com/Yalantis/uCrop",
"Description": " Image Cropping Library " "Description": " Image Cropping Library "
}, },
{ {
"Name": "js-spark-md5", "Name": "js-spark-md5",
"License": "MIT", "License": "MIT",
"License File": "https://github.com/satazor/js-spark-md5/blob/master/LICENSE", "License File": "LICENSE",
"Version Number": "v3.0.2", "Version Number": "v3.0.2",
"Owner" : "satazor", "Owner" : "xiafeng@huawei.com",
"Upstream URL": "https://github.com/satazor/js-spark-md5", "Upstream URL": "https://github.com/satazor/js-spark-md5",
"Description": "Lightning fast normal and incremental md5 for javascript" "Description": "Lightning fast normal and incremental md5 for javascript"
} }

View File

@ -264,6 +264,17 @@ ImageKnifeAnimatorComponent({
}),animatorOption:this.animatorOption }),animatorOption:this.animatorOption
}).width(300).height(300).backgroundColor(Color.Orange).margin({top:30}) }).width(300).height(300).backgroundColor(Color.Orange).margin({top:30})
``` ```
#### 11.图片降采样 示例
```
ImageKnifeComponent({
imageKnifeOption:new ImageKnifeOption({
loadSrc:$r("app.media.pngSample"),
placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed'),
downsampleOf: DownsampleStrategy.NONE
}),animatorOption:this.animatorOption
}).width(300).height(300)
```
#### Reuse Scenario #### Reuse Scenario
Clear the component content in the **aboutToRecycle** lifecycle and trigger image loading through watch observeration. Clear the component content in the **aboutToRecycle** lifecycle and trigger image loading through watch observeration.
## Available APIs ## Available APIs
@ -308,7 +319,17 @@ Clear the component content in the **aboutToRecycle** lifecycle and trigger imag
| drawingColorFilter | ColorFilter | Drawing color filter. Optional. | | drawingColorFilter | ColorFilter | Drawing color filter. Optional. |
| onComplete | (event:EventImage \| undefined)=>void | Callback for image loading completion. Optional. | | onComplete | (event:EventImage \| undefined)=>void | Callback for image loading completion. Optional. |
| onLoadListener | onLoadStart:()=>void,onLoadSuccess:(data:string\|Pixelmap)=>void | Callback for image loading events. Optional. | | onLoadListener | onLoadStart:()=>void,onLoadSuccess:(data:string\|Pixelmap)=>void | Callback for image loading events. Optional. |
| downsampleOf | DownsampleStrategy | 降采样(可选) |
### 降采样类型
| 类型 | 相关描述 |
|---------------------|-------------------|
| NONE | 不进行降采样 |
| AT_MOST | 请求尺寸大于实际尺寸不进行放大 |
| FIT_CENTER_MEMORY | 两边自适应内存优先 |
| FIT_CENTER_QUALITY | 两边自适应质量优先 |
| CENTER_OUTSIDE_MEMORY | 宽高缩放比最大的比例,进行缩放适配内存优先 |
| CENTER_OUTSIDE_QUALITY | 宽高缩放比最大的比例,进行缩放适配质量优先 |
| AT_LEAST | 根据宽高的最小的比例,进行适配 |
### ImageKnife ### ImageKnife
| Parameter | Type | Description | | Parameter | Type | Description |

View File

@ -7,9 +7,8 @@
{ {
"name": "default", "name": "default",
"signingConfig": "default", "signingConfig": "default",
"compileSdkVersion": "5.0.0(12)", "compileSdkVersion": 12,
"compatibleSdkVersion": "5.0.0(12)", "compatibleSdkVersion": 12
"runtimeOS": "HarmonyOS",
} }
], ],
"buildModeSet": [ "buildModeSet": [
@ -38,6 +37,10 @@
"name": "library", "name": "library",
"srcPath": "./library" "srcPath": "./library"
}, },
{
"name": "gpu_transform",
"srcPath": "./gpu_transform"
},
{ {
"name": "sharedlibrary", "name": "sharedlibrary",
"srcPath": "./sharedlibrary", "srcPath": "./sharedlibrary",

View File

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { DownsampleStrategy } from '@ohos/imageknife';
import { IEngineKey, ImageKnifeOption, PixelMapTransformation,SparkMD5 ,ImageKnifeRequestSource} from '@ohos/libraryimageknife'; import { IEngineKey, ImageKnifeOption, PixelMapTransformation,SparkMD5 ,ImageKnifeRequestSource} from '@ohos/libraryimageknife';
//全局自定义key demo //全局自定义key demo
@ -35,6 +36,9 @@ export class CustomEngineKeyImpl implements IEngineKey {
if (imageKnifeOption.transformation) { if (imageKnifeOption.transformation) {
key += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";" key += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";"
} }
if ((imageKnifeOption.downsampleOf !== DownsampleStrategy.NONE && imageKnifeOption.downsampleOf !== undefined)) {
key += "downsampleOf" + imageKnifeOption.downsampleOf +"width="+width+"height="+ height
}
} }
return key return key
} }

View File

@ -17,7 +17,7 @@ import hilog from '@ohos.hilog';
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want'; import Want from '@ohos.app.ability.Want';
import window from '@ohos.window'; import window from '@ohos.window';
import { ImageKnife, InitImageKnife } from '@ohos/libraryimageknife'; import { ImageKnife, InitImageKnife, LogUtil } from '@ohos/libraryimageknife';
import { CustomEngineKeyImpl } from '../common/CustomEngineKeyImpl'; import { CustomEngineKeyImpl } from '../common/CustomEngineKeyImpl';
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base' import { BusinessError } from '@ohos.base'

View File

@ -0,0 +1,214 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DownsampleStrategy, ImageKnifeOption, } from '@ohos/imageknife';
import { ImageKnifeComponent } from '@ohos/libraryimageknife';
import { image } from '@kit.ImageKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { Downsampler } from '@ohos/imageknife/src/main/ets/downsampling/Downsampler';
import { FileTypeUtil } from '@ohos/imageknife/src/main/ets/utils/FileTypeUtil';
@Entry
@ComponentV2
struct DownSamplePage {
@Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.startIcon'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain
})
isBrightness: boolean = false
@Local beforeSampling: number = 0
@Local afterSampling: number = 0
@Local SamplingList: SamplingType[] = [
new SamplingType(7, "AT_LEAST"),
new SamplingType(1, "AT_MOST"),
new SamplingType(2, "FIT_CENTER_MEMORY"),
new SamplingType(4, "FIT_CENTER_QUALITY"),
new SamplingType(5, "CENTER_OUTSIDE_MEMORY"),
new SamplingType(6, "CENTER_OUTSIDE_QUALITY"),
new SamplingType(0, "NONE"),
]
@Local checked: boolean = false
updateImageKnifeOption(value: string) {
if (value === 'NONE') {
this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.NONE
})
this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.pngSample'))
} else if (value === 'AT_MOST') {
this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.AT_MOST
})
this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.pngSample'))
} else if (value === 'FIT_CENTER_MEMORY') {
this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.FIT_CENTER_MEMORY
})
this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.pngSample'))
} else if (value === 'FIT_CENTER_QUALITY') {
this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.FIT_CENTER_QUALITY
})
this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.pngSample'))
} else if (value === 'CENTER_OUTSIDE_MEMORY') {
this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.CENTER_OUTSIDE_MEMORY
})
this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.pngSample'))
} else if (value === 'CENTER_OUTSIDE_QUALITY') {
this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.CENTER_OUTSIDE_QUALITY
})
this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.pngSample'))
} else {
this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.AT_LEAST
})
this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.pngSample'))
}
}
async afterSamplingFunc(imgs: Resource) {
let img: Uint8Array = await getContext(this).resourceManager.getMediaContent(imgs);
let imageSource: image.ImageSource = image.createImageSource(img.buffer.slice(0));
let fileTypeUtil = new FileTypeUtil();
let typeValue = fileTypeUtil.getFileType(img.buffer.slice(0)) as string;
let decodingOptions: image.DecodingOptions = {
editable: true,
desiredPixelFormat: 3,
}
let imageInfo = await imageSource.getImageInfo()
if (this.imageKnifeOption.downsampleOf !== DownsampleStrategy.NONE){
let reqSize =
new Downsampler().calculateScaling(typeValue, imageInfo.size.width, imageInfo.size.height, 300,
300, this.imageKnifeOption.downsampleOf)
decodingOptions = {
editable: true,
desiredSize: {
width: reqSize.width,
height: reqSize.height
}
}
}
// 创建pixelMap
imageSource.createPixelMap(decodingOptions).then((pixelMap: image.PixelMap) => {
this.afterSampling = pixelMap.getPixelBytesNumber()
}).catch((err: BusinessError) => {
console.error("Failed to create PixelMap")
});
}
async originalPixMap(imgs: Resource,) {
let img: Uint8Array = await getContext(this).resourceManager.getMediaContent(imgs);
let imageSource: image.ImageSource = image.createImageSource(img.buffer.slice(0));
let decodingOptions: image.DecodingOptions = {
editable: true,
desiredPixelFormat: 3,
}
// 创建pixelMap
imageSource.createPixelMap(decodingOptions).then((pixelMap: image.PixelMap) => {
this.beforeSampling = pixelMap.getPixelBytesNumber()
}).catch((err: BusinessError) => {
console.error("Failed to create PixelMap")
});
}
getResourceString(res:Resource){
return getContext().resourceManager.getStringSync(res.id)
}
build() {
Scroll() {
Column() {
ForEach(this.SamplingList, (item: SamplingType, index) => {
Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
Radio({ value: item.value + 'radio', group: 'radioGroup' })
.height(50)
.width(50)
.checked(this.checked)
.onClick(() => {
this.updateImageKnifeOption(item.value)
})
Text(this.getResourceString($r('app.string.Sampling_pecification'))+ item.value).fontSize(20)
}
}, (item: SamplingType) => JSON.stringify(item))
Column() {
Text(`${this.getResourceString($r('app.string.Unreal_samples'))}${this.beforeSampling}`).fontSize(20)
Text(`${ this.getResourceString($r('app.string.After_the_sampling'))}${this.afterSampling}`).fontSize(20)
}
ImageKnifeComponent({
imageKnifeOption: this.imageKnifeOption
})
.height(300)
.width(300)
.borderWidth(1)
.borderColor(Color.Pink)
}
}
.height('100%')
.width('100%')
}
}
class SamplingType {
key: number
value: string
constructor(key: number, value: string) {
this.key = key
this.value = value
}
}

View File

@ -12,14 +12,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { AnimatorOption, ImageKnifeAnimatorComponent } from "@ohos/libraryimageknife" import { AnimatorOption, ImageKnifeAnimatorComponent,ImageKnifeOption } from "@ohos/libraryimageknife"
@Entry @Entry
@Component @ComponentV2
struct ImageAnimatorPage { struct ImageAnimatorPage {
@State animatorOption: AnimatorOption = { @Local animatorOption: AnimatorOption = new AnimatorOption({
state: AnimationStatus.Running, state: AnimationStatus.Running,
iterations: 1, iterations: -1,
onFinish:()=>{ onFinish:()=>{
console.log("ImageKnifeAnimatorComponent animatorOption onFinish") console.log("ImageKnifeAnimatorComponent animatorOption onFinish")
}, },
@ -35,58 +35,58 @@ struct ImageAnimatorPage {
onRepeat:()=>{ onRepeat:()=>{
console.log("ImageKnifeAnimatorComponent animatorOption onRepeat") console.log("ImageKnifeAnimatorComponent animatorOption onRepeat")
} }
} })
@State animatorOption1: AnimatorOption = { @Local animatorOption1: AnimatorOption = new AnimatorOption({
state: AnimationStatus.Initial state: AnimationStatus.Initial
} })
@State animatorOption2: AnimatorOption = { @Local animatorOption2: AnimatorOption = new AnimatorOption({
state: AnimationStatus.Initial, state: AnimationStatus.Initial,
reverse: true reverse: true
} })
build() { build() {
Column(){ Column(){
Flex(){ Flex(){
Button("播放").onClick(()=>{ Button($r('app.string.Play')).onClick(()=>{
this.animatorOption.state = AnimationStatus.Running this.animatorOption.state = AnimationStatus.Running
}) })
Button("暂停").onClick(()=>{ Button($r('app.string.Pause')).onClick(()=>{
this.animatorOption.state = AnimationStatus.Paused this.animatorOption.state = AnimationStatus.Paused
}) })
Button("停止").onClick(()=>{ Button($r('app.string.Stop')).onClick(()=>{
this.animatorOption.state = AnimationStatus.Stopped this.animatorOption.state = AnimationStatus.Stopped
}) })
Button("无限循环").onClick(()=>{ Button($r('app.string.Infinite_loop')).onClick(()=>{
this.animatorOption.iterations = -1 this.animatorOption.iterations = -1
}) })
Button("播放一次").onClick(()=>{ Button($r('app.string.Play_once')).onClick(()=>{
this.animatorOption.iterations = 1 this.animatorOption.iterations = 1
}) })
Button("播放两次").onClick(()=>{ Button($r('app.string.Play_twice')).onClick(()=>{
this.animatorOption.iterations = 2 this.animatorOption.iterations = 2
}) })
} }
ImageKnifeAnimatorComponent({ ImageKnifeAnimatorComponent({
imageKnifeOption:{ imageKnifeOption:new ImageKnifeOption({
loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658", loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed') errorholderSrc:$r('app.media.failed')
},animatorOption:this.animatorOption }),animatorOption:this.animatorOption
}).width(300).height(300).backgroundColor(Color.Orange).margin({top:30}) }).width(200).height(200).backgroundColor(Color.Orange).margin({top:30})
Text($r('app.string.Display_the_first_frame')).fontSize(20) Text($r('app.string.Display_the_first_frame')).fontSize(20)
ImageKnifeAnimatorComponent({ ImageKnifeAnimatorComponent({
imageKnifeOption:{ imageKnifeOption:new ImageKnifeOption({
loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658", loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed') errorholderSrc:$r('app.media.failed')
},animatorOption:this.animatorOption1 }),animatorOption:this.animatorOption1
}).width(200).height(200).backgroundColor(Color.Orange).margin({top:30}) }).width(200).height(200).backgroundColor(Color.Orange).margin({top:30})
Text($r('app.string.Display_the_last_frame')).fontSize(20) Text($r('app.string.Display_the_last_frame')).fontSize(20)
ImageKnifeAnimatorComponent({ ImageKnifeAnimatorComponent({
imageKnifeOption:{ imageKnifeOption:new ImageKnifeOption({
loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658", loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed') errorholderSrc:$r('app.media.failed')
},animatorOption:this.animatorOption2 }),animatorOption:this.animatorOption2
}).width(200).height(200).backgroundColor(Color.Orange).margin({top:30}) }).width(200).height(200).backgroundColor(Color.Orange).margin({top:30})
}.width("100%").height("100%") }.width("100%").height("100%")
} }

View File

@ -35,17 +35,17 @@ import {
import { collections } from '@kit.ArkTS' import { collections } from '@kit.ArkTS'
@Entry @Entry
@Component @ComponentV2
struct ImageTransformation { struct ImageTransformation {
@State imageKnifeOption: ImageKnifeOption = { @Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.pngSample'), loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain objectFit: ImageFit.Contain
} })
@State isRound: boolean = false; @Local isRound: boolean = false;
@State isContrast: boolean = false; @Local isContrast: boolean = false;
@State isRotate: boolean = false; @Local isRotate: boolean = false;
isBlur: boolean = false isBlur: boolean = false
isBrightness: boolean = false isBrightness: boolean = false
isGrayScale: boolean = false; isGrayScale: boolean = false;
@ -412,14 +412,14 @@ struct ImageTransformation {
if (this.isMask) { if (this.isMask) {
transformations.push(new MaskTransformation($r('app.media.mask_starfish'))); transformations.push(new MaskTransformation($r('app.media.mask_starfish')));
} }
this.imageKnifeOption = { this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.pngSample'), loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain, objectFit: ImageFit.Contain,
border: { radius: this.isRound ? { topLeft: 50, bottomRight: 50 } : 0 }, border: { radius: this.isRound ? { topLeft: 50, bottomRight: 50 } : 0 },
transformation: transformations.length > 0 ? new MultiTransTransformation(transformations) : undefined transformation: transformations.length > 0 ? new MultiTransTransformation(transformations) : undefined
} })
if (this.isCropCircle) { if (this.isCropCircle) {
this.imageKnifeOption.objectFit = ImageFit.Cover; this.imageKnifeOption.objectFit = ImageFit.Cover;
this.imageKnifeOption.border = { radius: 150 }; this.imageKnifeOption.border = { radius: 150 };

View File

@ -15,156 +15,172 @@
import router from '@system.router'; import router from '@system.router';
@Entry @Entry
@Component @ComponentV2
struct Index { struct Index {
getResourceString(res: Resource) {
getResourceString(res:Resource){
return getContext().resourceManager.getStringSync(res.id) return getContext().resourceManager.getStringSync(res.id)
} }
aboutToAppear(): void { aboutToAppear(): void {
} }
build() { build() {
Scroll(){ Scroll() {
Column() { Column() {
Button($r('app.string.Test_ImageAnimator')).onClick(()=>{ Button($r('app.string.Test_ImageAnimator')).onClick(() => {
router.push({ router.push({
uri: 'pages/ImageAnimatorPage', uri: 'pages/ImageAnimatorPage',
}); });
}) })
Button($r('app.string.Test_multiple_images')).margin({top:10}).onClick(()=>{ Button($r('app.string.Test_multiple_images')).margin({ top: 10 }).onClick(() => {
router.push({ router.push({
uri: 'pages/TestCommonImage', uri: 'pages/TestCommonImage',
}); });
}) })
Button($r('app.string.Test_Task_error')).margin({top:10}).onClick(()=>{ Button(this.getResourceString($r('app.string.Multiple_images')) + " + reuse + LazyForeach")
router.push({ .margin({ top: 10 })
uri: 'pages/TestTaskResourcePage', .onClick(() => {
}); router.push({
}) uri: 'pages/UserPage',
Button($r('app.string.Test_HSP')).margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/TestHspPreLoadImage',
}); });
}) })
Button($r('app.string.Test_SingleImage')).margin({top:10}).onClick(()=>{ Button($r('app.string.Test_SingleImage')).margin({ top: 10 }).onClick(() => {
router.push({ router.push({
uri: 'pages/SingleImage', uri: 'pages/SingleImage',
}); });
}) })
Button($r('app.string.Test_custom_download')).margin({top:10}).onClick(()=>{ Button($r('app.string.Image_Downsampling_Functionality')).margin({top:10}).onClick(()=>{
router.push({ router.push({
uri: 'pages/TestSetCustomImagePage', uri: 'pages/DownSamplePage',
}); });
}) })
Button(this.getResourceString($r('app.string.Multiple_images')) + " + LazyForEach").margin({top:10}).onClick(()=>{ Button($r('app.string.Display_long_image')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/ManyPhotoShowPage',
});
})
Button(this.getResourceString($r('app.string.Multiple_images')) + " + reuse + LazyForeach").margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/UserPage',
});
})
Button($r('app.string.Display_long_image')).margin({top:10}).onClick(()=>{
router.push({ router.push({
uri: 'pages/LongImagePage', uri: 'pages/LongImagePage',
}); });
}) })
Button($r('app.string.Image_scaling')).margin({top:10}).onClick(()=>{ Button($r('app.string.Image_Transformation')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TransformPage',
});
})
Button(this.getResourceString($r('app.string.Message_list')) + " + List").margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/TestImageFlash',
});
})
Button($r('app.string.Custom_cache_key')).margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/SignatureTestPage',
});
})
Button($r('app.string.Preloading_images_to_cache')).margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/TestPrefetchToFileCache',
});
})
Button($r('app.string.Retrieve_image_display_from_cache')).margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/TestIsUrlExist',
});
})
Button($r('app.string.Test_single_request_header')).margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/TestHeader',
});
})
Button($r('app.string.Test_write_cache_strategy')).margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/TestWriteCacheStage',
});
})
Button($r('app.string.Image_Transformation')).margin({top:10}).onClick(()=>{
router.push({ router.push({
uri: 'pages/ImageTransformation', uri: 'pages/ImageTransformation',
}); });
}) })
Button($r('app.string.Test_media_URL')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/dataShareUriLoadPage',
Button($r('app.string.Different_ObjectFit')).margin({top:10}).onClick(()=>{ });
})
Button($r('app.string.Different_ObjectFit')).margin({ top: 10 }).onClick(() => {
router.push({ router.push({
uri: 'pages/ObjectFitPage', uri: 'pages/ObjectFitPage',
}); });
}) })
Button($r('app.string.Custom_cache_key')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/SignatureTestPage',
Button($r('app.string.Test_image_loading_success_or_failure_events')).margin({top:10}).onClick(()=>{ });
})
Button($r('app.string.Test_image_loading_success_or_failure_events')).margin({ top: 10 }).onClick(() => {
router.push({ router.push({
uri: 'pages/LoadStatePage', uri: 'pages/LoadStatePage',
}) })
}) })
Button($r('app.string.Image_scaling')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TransformPage',
Button($r('app.string.Test_removing_image_cache_interface')).margin({top:10}).onClick(()=>{ });
})
Button($r('app.string.Test_HSP')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TestHspPreLoadImage',
});
})
Button($r('app.string.Test_custom_download')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TestSetCustomImagePage',
});
})
Button(this.getResourceString($r('app.string.Message_list')) + " + List").margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TestImageFlash',
});
})
Button($r('app.string.Preloading_images_to_cache')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TestPrefetchToFileCache',
});
})
Button($r('app.string.Retrieve_image_display_from_cache')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TestIsUrlExist',
});
})
Button($r('app.string.Test_single_request_header')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TestHeader',
});
})
Button($r('app.string.Test_write_cache_strategy')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TestWriteCacheStage',
});
})
Button($r('app.string.Test_removing_image_cache_interface')).margin({ top: 10 }).onClick(() => {
router.push({ router.push({
uri: 'pages/TestRemoveCache', uri: 'pages/TestRemoveCache',
}); });
}) })
Button($r('app.string.Test_error_image_display')).margin({top:10}).onClick(()=>{ Button($r('app.string.Test_error_image_display')).margin({ top: 10 }).onClick(() => {
router.push({ router.push({
uri: 'pages/TestErrorHolderPage', uri: 'pages/TestErrorHolderPage',
}); });
}) })
Button($r('app.string.Test_media_URL')).margin({top:10}).onClick(()=>{ Button($r('app.string.Test_Task_error')).margin({ top: 10 }).onClick(() => {
router.push({ router.push({
uri: 'pages/dataShareUriLoadPage', uri: 'pages/TestTaskResourcePage',
});
})
Button($r('app.string.test_cache_btn')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TestCacheDataPage',
});
})
Button($r('app.string.test_change_color_btn')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TestChangeColorPage',
});
})
Button($r('app.string.test_cancel_callback_btn')).margin({ top: 10 }).onClick(() => {
router.push({
uri: 'pages/TestLoadCancelListenerPage',
}); });
}) })
} }
} .width('100%') }.width('100%')
.height('100%') .height('100%')
} }
} }

View File

@ -15,11 +15,11 @@
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'; import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
@Entry @Entry
@Component @ComponentV2
struct ListPage { struct ListPage {
private data: string[] = [] private data: string[] = []
@State ImageKnifeOption: ImageKnifeOption = { loadSrc: $r('app.media.startIcon')} @Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption({ loadSrc: $r('app.media.startIcon')})
aboutToAppear(): void { aboutToAppear(): void {

View File

@ -16,12 +16,12 @@ import { ImageKnifeComponent, ImageKnifeOption } from "@ohos/libraryimageknife"
import matrix4 from '@ohos.matrix4' import matrix4 from '@ohos.matrix4'
@Entry @Entry
@Component @ComponentV2
struct LoadStatePage { struct LoadStatePage {
starTime:number = new Date().getTime() starTime:number = new Date().getTime()
@State ImageKnifeOption: ImageKnifeOption = { @Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r("app.media.rabbit"), loadSrc: $r("app.media.rabbit"),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
@ -35,22 +35,22 @@ struct LoadStatePage {
}, },
}, },
border: { radius: 50 } border: { radius: 50 }
} })
@State imageKnifeOption1: ImageKnifeOption = { @Local imageKnifeOption1: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.startIcon') loadSrc: $r('app.media.startIcon')
} })
@State message: string = "" @Local message: string = ""
@State currentWidth: number = 200 @Local currentWidth: number = 200
@State currentHeight: number = 200 @Local currentHeight: number = 200
@State typeValue: string = "" @Local typeValue: string = ""
build() { build() {
Column() { Column() {
Text('测试失败场景请先关闭网络,并保证本地没有此网络图片的缓存') Text($r('app.string.TIPS'))
.margin({ top: 20 }) .margin({ top: 20 })
Row() { Row() {
Button('测试失败/成功场景') Button($r('app.string.Test_failure_success'))
.onClick(() => { .onClick(() => {
this.ImageKnifeOption = { this.ImageKnifeOption = new ImageKnifeOption({
loadSrc: "https://www.openharmony.cn/_nuxt/img/logo.dcf95b3.png", loadSrc: "https://www.openharmony.cn/_nuxt/img/logo.dcf95b3.png",
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
@ -75,15 +75,17 @@ struct LoadStatePage {
onComplete:(event)=>{ onComplete:(event)=>{
console.error("Load onComplete width:"+event?.width , " height:"+event?.height , " componentWidth:"+event?.componentWidth," componentHeight:" + event?.componentHeight); console.error("Load onComplete width:"+event?.width , " height:"+event?.height , " componentWidth:"+event?.componentWidth," componentHeight:" + event?.componentHeight);
} }
} })
}) })
} }
.margin({ top: 20 }) .margin({ top: 20 })
Text(this.typeValue) Text($r('app.string.image_format',this.typeValue))
Text($r('app.string.image_width',this.currentWidth))
Text($r('app.string.image_height',this.currentHeight))
ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption }).height(this.currentHeight).width(this.currentWidth) ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption }).height(this.currentHeight).width(this.currentWidth)
.margin({ top: 20 }) .margin({ top: 20 })
Button("自定义下载失败").onClick(()=>{ Button($r('app.string.Custom_download_failed')).onClick(()=>{
this.imageKnifeOption1 = { this.imageKnifeOption1 = new ImageKnifeOption({
loadSrc: "abc", loadSrc: "abc",
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed'), errorholderSrc:$r('app.media.failed'),
@ -93,7 +95,7 @@ struct LoadStatePage {
this.message = "err:" + err this.message = "err:" + err
} }
} }
} })
}).margin({ top: 20 }) }).margin({ top: 20 })
Text(this.message).fontSize(20).margin({ top: 20 }) Text(this.message).fontSize(20).margin({ top: 20 })
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).height(this.currentHeight).width(this.currentWidth) ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).height(this.currentHeight).width(this.currentWidth)

View File

@ -12,10 +12,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { ImageKnifeComponent } from '@ohos/libraryimageknife' import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife'
@Entry @Entry
@Component @ComponentV2
struct LongImagePage { struct LongImagePage {
build() { build() {
@ -25,13 +25,13 @@ struct LongImagePage {
// Image($r("app.media.aaa")).objectFit(ImageFit.Auto).width(200) // Image($r("app.media.aaa")).objectFit(ImageFit.Auto).width(200)
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: new ImageKnifeOption({
loadSrc:"https://wx2.sinaimg.cn/mw690/006HyQKGgy1hnqp08dw09j30u04twu0x.jpg", loadSrc:"https://wx2.sinaimg.cn/mw690/006HyQKGgy1hnqp08dw09j30u04twu0x.jpg",
//src:$r("app.media.aaa"), //src:$r("app.media.aaa"),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"), errorholderSrc: $r("app.media.failed"),
objectFit: ImageFit.Auto objectFit: ImageFit.Auto
} })
}) })
} }
.height('100%') .width('100%') .height('100%') .width('100%')

File diff suppressed because it is too large Load Diff

View File

@ -15,49 +15,49 @@
import { ImageKnife, ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife' import { ImageKnife, ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'
@Entry @Entry
@Component @ComponentV2
struct ObjectFitPage { struct ObjectFitPage {
@State imageKnifeOption: ImageKnifeOption = { @Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r("app.media.app_icon"), loadSrc: $r("app.media.app_icon"),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Fill objectFit: ImageFit.Fill
} })
build() { build() {
Column() { Column() {
Button("主图Fill拉伸填充").onClick(()=>{ Button($r('app.string.Main_image_Fill')).onClick(()=>{
this.imageKnifeOption = { this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r("app.media.app_icon"), loadSrc: $r("app.media.app_icon"),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Fill objectFit: ImageFit.Fill
} })
}) })
Button("占位图Contain保持比例填充").margin({top:10}).onClick(async () => { Button($r('app.string.Maintain_proportion_filling')).margin({top:10}).onClick(async () => {
ImageKnife.getInstance().removeAllMemoryCache() ImageKnife.getInstance().removeAllMemoryCache()
await ImageKnife.getInstance().removeAllFileCache() await ImageKnife.getInstance().removeAllFileCache()
this.imageKnifeOption = { this.imageKnifeOption = new ImageKnifeOption({
loadSrc: "https://wx2.sinaimg.cn/mw690/006HyQKGgy1hnqp08dw09j30u04twu0x.jpg", loadSrc: "https://wx2.sinaimg.cn/mw690/006HyQKGgy1hnqp08dw09j30u04twu0x.jpg",
placeholderSrc: $r("app.media.app_icon"), placeholderSrc: $r("app.media.app_icon"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Fill, objectFit: ImageFit.Fill,
placeholderObjectFit: ImageFit.Contain placeholderObjectFit: ImageFit.Contain
} })
}) })
Button("错误图None不变化").margin({top:10}).onClick(() => { Button($r('app.string.Error_graph_None')).margin({top:10}).onClick(() => {
this.imageKnifeOption = { this.imageKnifeOption = new ImageKnifeOption({
loadSrc: "http://xxxxx", loadSrc: "http://xxxxx",
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Fill, objectFit: ImageFit.Fill,
errorholderObjectFit: ImageFit.None errorholderObjectFit: ImageFit.None
} })
}) })
ImageKnifeComponent({ ImageKnifeComponent({

View File

@ -16,18 +16,18 @@ import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
@Entry @Entry
@Component @ComponentV2
struct SignatureTestPage { struct SignatureTestPage {
@State imageKnifeOption1: ImageKnifeOption = @Local imageKnifeOption1: ImageKnifeOption =new ImageKnifeOption(
{ {
loadSrc: $r('app.media.icon'), loadSrc: $r('app.media.icon'),
placeholderSrc:$r("app.media.loading"), placeholderSrc:$r("app.media.loading"),
}; });
@State imageKnifeOption2: ImageKnifeOption = @Local imageKnifeOption2: ImageKnifeOption =new ImageKnifeOption(
{ {
loadSrc: $r('app.media.icon'), loadSrc: $r('app.media.icon'),
placeholderSrc:$r("app.media.loading"), placeholderSrc:$r("app.media.loading"),
}; });
build() { build() {
Scroll() { Scroll() {
@ -37,11 +37,11 @@ struct SignatureTestPage {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button($r('app.string.Load')) Button($r('app.string.Load'))
.onClick(() => { .onClick(() => {
this.imageKnifeOption1 = { this.imageKnifeOption1 = new ImageKnifeOption({
loadSrc: 'https://img-blog.csdn.net/20140514114029140', loadSrc: 'https://img-blog.csdn.net/20140514114029140',
placeholderSrc:$r("app.media.loading"), placeholderSrc:$r("app.media.loading"),
signature: "1" signature: "1"
} })
}).margin({ top: 5, left: 3 }) }).margin({ top: 5, left: 3 })
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).width(300).height(300) ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).width(300).height(300)
}.width('100%').backgroundColor(Color.Pink) }.width('100%').backgroundColor(Color.Pink)
@ -50,11 +50,11 @@ struct SignatureTestPage {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button($r('app.string.Load')) Button($r('app.string.Load'))
.onClick(() => { .onClick(() => {
this.imageKnifeOption2 = { this.imageKnifeOption2 = new ImageKnifeOption({
loadSrc: 'https://img-blog.csdn.net/20140514114029140', loadSrc: 'https://img-blog.csdn.net/20140514114029140',
placeholderSrc:$r("app.media.loading"), placeholderSrc:$r("app.media.loading"),
signature: new Date().getTime().toString() signature: new Date().getTime().toString()
} })
}).margin({ top: 5, left: 3 }) }).margin({ top: 5, left: 3 })
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 }).width(300).height(300) ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 }).width(300).height(300)
}.width('100%').backgroundColor(Color.Pink) }.width('100%').backgroundColor(Color.Pink)

View File

@ -12,19 +12,19 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { ImageKnifeComponent,BlurTransformation } from '@ohos/libraryimageknife'; import { ImageKnifeComponent,BlurTransformation,ImageKnifeOption } from '@ohos/libraryimageknife';
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
import { common2D, drawing } from '@kit.ArkGraphics2D'; import { common2D, drawing } from '@kit.ArkGraphics2D';
@Entry @Entry
@Component @ComponentV2
struct SingleImage { struct SingleImage {
resource: string = "app.media.svgSample" resource: string = "app.media.svgSample"
scroller: Scroller = new Scroller; scroller: Scroller = new Scroller;
localFile: string = getContext(this).filesDir + "/icon.png" localFile: string = getContext(this).filesDir + "/icon.png"
@State pixelMap:PixelMap | undefined = undefined; @Local pixelMap:PixelMap | undefined = undefined;
@State DrawingColorFilter: ColorFilter | undefined = undefined @Local DrawingColorFilter: ColorFilter | undefined = undefined
private color: common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 }; private color: common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
aboutToAppear(): void { aboutToAppear(): void {
// 拷贝本地文件 // 拷贝本地文件
@ -46,12 +46,12 @@ struct SingleImage {
.fontSize(30) .fontSize(30)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: new ImageKnifeOption({
loadSrc: $r("app.media.svgSample"), loadSrc: $r("app.media.svgSample"),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"), errorholderSrc: $r("app.media.failed"),
objectFit: ImageFit.Contain objectFit: ImageFit.Contain
} })
}).width(100).height(100) }).width(100).height(100)
.onClick(()=>{ .onClick(()=>{
this.DrawingColorFilter = drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN); this.DrawingColorFilter = drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN);
@ -60,48 +60,48 @@ struct SingleImage {
.fontSize(30) .fontSize(30)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: new ImageKnifeOption({
loadSrc: this.localFile, loadSrc: this.localFile,
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"), errorholderSrc: $r("app.media.failed"),
objectFit: ImageFit.Contain objectFit: ImageFit.Contain
} })
}).width(100).height(100) }).width(100).height(100)
Text($r('app.string.Network_images')) Text($r('app.string.Network_images'))
.fontSize(30) .fontSize(30)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: new ImageKnifeOption({
loadSrc:"https://www.openharmony.cn/_nuxt/img/logo.dcf95b3.png", loadSrc:"https://www.openharmony.cn/_nuxt/img/logo.dcf95b3.png",
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"), errorholderSrc: $r("app.media.failed"),
objectFit: ImageFit.Contain, objectFit: ImageFit.Contain,
progressListener:(progress:number)=>{console.info("ImageKnife:: call back progress = " + progress)} progressListener:(progress:number)=>{console.info("ImageKnife:: call back progress = " + progress)}
} })
}).width(100).height(100) }).width(100).height(100)
Text($r('app.string.Custom_network_download')) Text($r('app.string.Custom_network_download'))
.fontSize(30) .fontSize(30)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: new ImageKnifeOption({
loadSrc: "https://file.atomgit.com/uploads/user/1704857786989_8994.jpeg", loadSrc: "https://file.atomgit.com/uploads/user/1704857786989_8994.jpeg",
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"), errorholderSrc: $r("app.media.failed"),
objectFit: ImageFit.Contain, objectFit: ImageFit.Contain,
customGetImage: custom, customGetImage: custom,
transformation: new BlurTransformation(10) transformation: new BlurTransformation(10)
} })
}).width(100).height(100) }).width(100).height(100)
Text($r('app.string.PixelMap_loads_images')) Text($r('app.string.PixelMap_loads_images'))
.fontSize(30) .fontSize(30)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: new ImageKnifeOption({
loadSrc: this.pixelMap!, loadSrc: this.pixelMap!,
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"), errorholderSrc: $r("app.media.failed"),
objectFit: ImageFit.Contain, objectFit: ImageFit.Contain,
} })
}).width(100).height(100) }).width(100).height(100)
} }
.width('100%') .width('100%')

View File

@ -0,0 +1,140 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ImageKnife, CacheStrategy, ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';
@Entry
@ComponentV2
struct TestCacheDataPage {
@Local cacheUpLimit: number = 0;
@Local currentNum: number = 0;
@Local currentSize: number = 0;
@Local currentWidth: number = 200
@Local currentHeight: number = 200
@Local markersLimitText: string = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
@Local markersNumText: string = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
@Local markersSizeText: string = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
@Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: "",
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadFailed: (err) => {
console.error("Load Failed Reason: " + err);
},
onLoadSuccess: (data) => {
return data;
},
},
border: { radius: 50 }
})
aboutToAppear(): void {
ImageKnife.getInstance().initFileCache(getContext(this), 256, 256 * 1024 * 1024, "ImageKnifeCache1")
}
build() {
Column() {
ImageKnifeComponent(
{ imageKnifeOption: this.ImageKnifeOption })
.height(this.currentHeight)
.width(this.currentWidth)
.margin({ top: 10 })
Button($r('app.string.load_memory'))
.onClick(() => {
this.ImageKnifeOption = new ImageKnifeOption({
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg",
objectFit: ImageFit.Contain,
writeCacheStrategy: CacheStrategy.Memory,
border: { radius: 50 },
})
})
Button($r('app.string.load_disk'))
.onClick(() => {
this.ImageKnifeOption = new ImageKnifeOption({
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg",
objectFit: ImageFit.Contain,
writeCacheStrategy: CacheStrategy.File,
border: { radius: 50 },
})
})
Text($r('app.string.cur_cache_limit', this.markersLimitText, this.cacheUpLimit))
.fontSize(20)
.margin({ bottom: 8 });
Text($r('app.string.cur_cache_image_num', this.markersNumText, this.currentNum))
.fontSize(20)
.margin({ bottom: 8 });
Text($r('app.string.cur_cache_size', this.markersSizeText, this.currentSize)).fontSize(20).margin({ bottom: 20 });
Button($r('app.string.get_cur_memory_limit')).onClick(() => {
let result = ImageKnife.getInstance().getCacheUpperLimit(CacheStrategy.Memory);
this.markersLimitText = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
if (result) {
this.cacheUpLimit = result / (1024 * 1024);
} else {
this.cacheUpLimit = 0;
}
}).margin({ bottom: 8 });
Button($r('app.string.get_img_number_of_cache')).onClick(() => {
let result = ImageKnife.getInstance().getCurrentPicturesNum(CacheStrategy.Memory);
this.markersNumText = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
if (result) {
this.currentNum = result;
} else {
this.currentNum = 0;
}
}).margin({ bottom: 8 });
Button($r('app.string.get_cur_memory_size')).onClick(() => {
let result = ImageKnife.getInstance().getCurrentCacheSize(CacheStrategy.Memory);
this.markersSizeText = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
if (result) {
this.currentSize = result / (1024 * 1024);
} else {
this.currentSize = 0;
}
}).margin({ bottom: 8 });
Button($r('app.string.get_cur_disk_limit')).onClick(() => {
let result = ImageKnife.getInstance().getCacheUpperLimit(CacheStrategy.File);
this.markersLimitText = getContext(this).resourceManager.getStringSync($r('app.string.disk'))
if (result) {
this.cacheUpLimit = result / (1024 * 1024);
} else {
this.cacheUpLimit = 0;
}
}).margin({ bottom: 8 });
Button($r('app.string.get_img_number_of_disk')).onClick(() => {
let result = ImageKnife.getInstance().getCurrentPicturesNum(CacheStrategy.File);
this.markersNumText = getContext(this).resourceManager.getStringSync($r('app.string.disk'))
if (result) {
this.currentNum = result;
} else {
this.currentNum = 0;
}
}).margin({ bottom: 8 });
Button($r('app.string.get_cur_disk_size')).onClick(() => {
let result = ImageKnife.getInstance().getCurrentCacheSize(CacheStrategy.File);
this.markersSizeText = getContext(this).resourceManager.getStringSync($r('app.string.disk'))
if (result) {
this.currentSize = result / (1024 * 1024);
} else {
this.currentSize = 0;
}
}).margin({ bottom: 8 });
}
.height('100%').width('100%').margin({ top: 50 })
}
}

View File

@ -0,0 +1,112 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { drawing, common2D } from '@kit.ArkGraphics2D';
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';
@Entry
@Component
struct TestChangeColorPage {
private imageOne: Resource = $r('app.media.ic_test_change_color_png');
private imageTwo: Resource = $r('app.media.ic_test_change_color_png');
@State src: Resource = this.imageOne
@State src2: Resource = this.imageTwo
@State color: common2D.Color = {
alpha: 255,
red: 255,
green: 1,
blue: 1
};
@State DrawingColorFilterFirst: ColorFilter | undefined = undefined
build() {
Column() {
Text($r('app.string.select_color_btn')).margin({ top: 20 })
Row() {
Button($r('app.string.red')).backgroundColor(Color.Red).margin(5).onClick(() => {
this.color = {
alpha: 255,
red: 255,
green: 1,
blue: 1
};
})
Button($r('app.string.yellow')).backgroundColor(Color.Yellow).margin(5).onClick(() => {
this.color = {
alpha: 255,
red: 255,
green: 255,
blue: 1
};
})
Button($r('app.string.green')).backgroundColor(Color.Green).margin(5).onClick(() => {
this.color = {
alpha: 255,
red: 1,
green: 255,
blue: 1
};
})
Button($r('app.string.blue')).backgroundColor(Color.Blue).margin(5).onClick(() => {
this.color = {
alpha: 255,
red: 1,
green: 1,
blue: 255
};
})
}
.width('100%')
.height(50)
.justifyContent(FlexAlign.Center)
Text($r('app.string.master_image')).margin({ top: 20 })
ImageKnifeComponent({
imageKnifeOption: new ImageKnifeOption({
loadSrc: this.src
})
}).width(110).height(110)
Text($r('app.string.click_img_to_change_color')).margin({ top: 30 })
ImageKnifeComponent({
imageKnifeOption: new ImageKnifeOption({
loadSrc: this.src,
drawingColorFilter: this.DrawingColorFilterFirst
})
})
.onClick(() => {
this.DrawingColorFilterFirst =
drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN);
}).width(110).height(110)
Text($r('app.string.test_non_svg_color')).margin({ top: 30 })
ImageKnifeComponent({
imageKnifeOption: new ImageKnifeOption({
loadSrc: $r('app.media.ic_test_change_color_png'),
drawingColorFilter: drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN)
})
}).width(110).height(110)
Text($r('app.string.test_svg_color')).margin({ top: 30 })
ImageKnifeComponent({
imageKnifeOption: new ImageKnifeOption({
loadSrc: $r("app.media.ic_test_change_color_svg"),
drawingColorFilter: drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN)
})
}).width(110).height(110)
}.width('100%').height('100%')
}
}

View File

@ -12,10 +12,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { ImageKnifeComponent } from '@ohos/libraryimageknife'; import { ImageKnifeComponent ,ImageKnifeOption} from '@ohos/libraryimageknife';
@Entry @Entry
@Component @ComponentV2
struct TestCommonImage { struct TestCommonImage {
private data: Array<string> = [] private data: Array<string> = []
aboutToAppear(): void { aboutToAppear(): void {
@ -30,13 +30,13 @@ struct TestCommonImage {
FlowItem() { FlowItem() {
Column(){ Column(){
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: new ImageKnifeOption({
loadSrc: item, loadSrc: item,
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"), errorholderSrc: $r("app.media.failed"),
objectFit: ImageFit.Contain, objectFit: ImageFit.Contain,
signature: "aaa" signature: "aaa"
} })
}).width("50%").height(200) }).width("50%").height(200)
} }
}.height(200) }.height(200)

View File

@ -12,34 +12,34 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { ImageKnifeComponent } from '@ohos/libraryimageknife' import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife'
@Entry @Entry
@Component @ComponentV2
struct TestErrorHolderPage { struct TestErrorHolderPage {
build() { build() {
Column() { Column() {
Text("ImageKnifeComponent1").fontSize(20) Text("ImageKnifeComponent1").fontSize(20)
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: new ImageKnifeOption({
loadSrc: "abc", loadSrc: "abc",
errorholderSrc:$r('app.media.failed') errorholderSrc:$r('app.media.failed')
} })
}).width(200).height(200) }).width(200).height(200)
Text("ImageKnifeComponent2").fontSize(20) Text("ImageKnifeComponent2").fontSize(20)
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: new ImageKnifeOption({
loadSrc: "abc", loadSrc: "abc",
errorholderSrc:$r('app.media.startIcon') errorholderSrc:$r('app.media.startIcon')
} })
}).width(200).height(200) }).width(200).height(200)
Text("ImageKnifeComponent2").fontSize(20) Text("ImageKnifeComponent2").fontSize(20)
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: new ImageKnifeOption({
loadSrc: "abc", loadSrc: "abc",
errorholderSrc:$r('app.media.mask_starfish') errorholderSrc:$r('app.media.mask_starfish')
} })
}).width(200).height(200) }).width(200).height(200)
} }
.height('100%') .width('100%') .height('100%') .width('100%')

View File

@ -15,9 +15,9 @@
import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife' import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife'
@Entry @Entry
@Component @ComponentV2
struct TestPrefetchToFileCachePage { struct TestPrefetchToFileCachePage {
@State imageKnifeOption: ImageKnifeOption = { @Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658", loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
headerOption:[ headerOption:[
@ -26,7 +26,7 @@ struct TestPrefetchToFileCachePage {
value:"单个" value:"单个"
} }
] ]
} })
build() { build() {
Column() { Column() {

View File

@ -15,7 +15,7 @@
import { IndexComponent } from "@ohos/libraryimageknife" import { IndexComponent } from "@ohos/libraryimageknife"
@Entry @Entry
@Component @ComponentV2
struct TestHspPreLoadImage { struct TestHspPreLoadImage {
build() { build() {
Column() { Column() {

View File

@ -12,9 +12,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { ImageKnifeComponent } from '@ohos/libraryimageknife' import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife'
@Observed @ObservedV2
export class MsgModel { export class MsgModel {
id: string id: string
cId: string cId: string
@ -30,10 +30,10 @@ export class MsgModel {
} }
@Reusable // @Reusable
@Component @ComponentV2
export struct MsgItem { export struct MsgItem {
count: number = 0 @Param count: number = 0
private data: Array<string> = [ private data: Array<string> = [
"http://e.hiphotos.baidu.com/image/pic/item/a1ec08fa513d2697e542494057fbb2fb4316d81e.jpg", "http://e.hiphotos.baidu.com/image/pic/item/a1ec08fa513d2697e542494057fbb2fb4316d81e.jpg",
"http://c.hiphotos.baidu.com/image/pic/item/30adcbef76094b36de8a2fe5a1cc7cd98d109d99.jpg", "http://c.hiphotos.baidu.com/image/pic/item/30adcbef76094b36de8a2fe5a1cc7cd98d109d99.jpg",
@ -59,37 +59,37 @@ export struct MsgItem {
build(){ build(){
if (this.count % 2 == 0 && this.count <6){ if (this.count % 2 == 0 && this.count <6){
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption:{ imageKnifeOption:new ImageKnifeOption({
loadSrc:$r("app.media.startIcon"), loadSrc:$r("app.media.startIcon"),
placeholderSrc:$r("app.media.loading") placeholderSrc:$r("app.media.loading")
},syncLoad:true }),syncLoad:true
}) })
}else if (this.count > 6 && this.count - 6 < this.data.length){ }else if (this.count > 6 && this.count - 6 < this.data.length){
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption:{ imageKnifeOption:new ImageKnifeOption({
loadSrc:this.data[this.count - 6], loadSrc:this.data[this.count - 6],
placeholderSrc:$r("app.media.loading") placeholderSrc:$r("app.media.loading")
},syncLoad:true }),syncLoad:true
}) })
}else { }else {
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption:{ imageKnifeOption:new ImageKnifeOption({
loadSrc:$r("app.media.pngSample"), loadSrc:$r("app.media.pngSample"),
placeholderSrc:$r("app.media.loading") placeholderSrc:$r("app.media.loading")
},syncLoad:true }),syncLoad:true
}) })
} }
} }
} }
@Entry @Entry
@Component @ComponentV2
struct ImageTestPage { struct ImageTestPage {
count : number = 0 count : number = 0
rCount: number = 0 rCount: number = 0
scroller: Scroller = new Scroller() scroller: Scroller = new Scroller()
@State list: MsgModel[] = [] @Local list: MsgModel[] = []
@State imageSize: number =100 @Local imageSize: number =100
handAdd(){ handAdd(){
this.count++ this.count++
const msgItem = new MsgModel('add_id'+this.count, 'addBody'+this.count,'cId'+ this.count) const msgItem = new MsgModel('add_id'+this.count, 'addBody'+this.count,'cId'+ this.count)

View File

@ -15,15 +15,15 @@
import { ImageKnifeComponent, ImageKnife, ImageKnifeOption, CacheStrategy } from '@ohos/libraryimageknife' import { ImageKnifeComponent, ImageKnife, ImageKnifeOption, CacheStrategy } from '@ohos/libraryimageknife'
@Entry @Entry
@Component @ComponentV2
struct TestIsUrlExist { struct TestIsUrlExist {
@State imageKnifeOption: ImageKnifeOption = { @Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.startIcon'), loadSrc: $r('app.media.startIcon'),
placeholderSrc: $r('app.media.loading'), placeholderSrc: $r('app.media.loading'),
errorholderSrc:$r('app.media.failed') errorholderSrc:$r('app.media.failed')
} })
@State source: PixelMap | string | Resource = $r("app.media.startIcon") @Local source: PixelMap | string | Resource = $r("app.media.startIcon")
@State source1: PixelMap | string | Resource = $r("app.media.startIcon") @Local source1: PixelMap | string | Resource = $r("app.media.startIcon")
build() { build() {
Column() { Column() {

View File

@ -0,0 +1,94 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';
@Entry
@ComponentV2
struct TestLoadCancelListenerPage {
@Local currentWidth: number = 200
@Local currentHeight: number = 200
@Local showChild: boolean = true;
@Local text: string = "";
@Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: "",
objectFit: ImageFit.Contain,
border: { radius: 50 }
})
build() {
Column() {
Text($r('app.string.onLoadCancel_reason', this.text)).margin(20).fontSize(15)
Button($r('app.string.rm_component_of_net'))
.margin(20)
.onClick(() => {
this.ImageKnifeOption = new ImageKnifeOption({
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg",
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadStart: () => {
this.showChild = false;
},
onLoadCancel: (res) => {
this.text = res
console.log("TestLoadCancelListenerPage----onLoadCancel> url:" + res)
}
},
border: { radius: 50 }
})
})
Button($r('app.string.component_display'))
.margin(20).onClick(() => {
this.text = "";
this.showChild = true;
this.ImageKnifeOption = new ImageKnifeOption({
loadSrc: "",
objectFit: ImageFit.Contain,
border: { radius: 50 }
})
})
Button($r('app.string.rm_component_of_local'))
.margin(20)
.onClick(() => {
this.ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.loading'),
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadStart: () => {
this.showChild = false;
},
onLoadCancel: (res) => {
this.text = res
console.log("TestLoadCancelListenerPage----onLoadCancel> url:" + res)
}
},
border: { radius: 50 }
})
})
if (this.showChild) {
ImageKnifeComponent(
{ imageKnifeOption: this.ImageKnifeOption })
.height(150)
.width(150)
.backgroundColor(Color.Orange)
.margin({ top: 20 })
}
}
.height('100%')
.width('100%')
}
}

View File

@ -15,19 +15,19 @@
import { ImageKnifeComponent,ImageKnife,ImageKnifeOption } from '@ohos/libraryimageknife' import { ImageKnifeComponent,ImageKnife,ImageKnifeOption } from '@ohos/libraryimageknife'
@Entry @Entry
@Component @ComponentV2
struct TestPrefetchToFileCachePage { struct TestPrefetchToFileCachePage {
@State imageKnifeOption: ImageKnifeOption = { @Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc:$r('app.media.startIcon'), loadSrc:$r('app.media.startIcon'),
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed') errorholderSrc:$r('app.media.failed')
} })
async preload(url:string) { async preload(url:string) {
let fileCachePath = await ImageKnife.getInstance().preLoadCache(url) let fileCachePath = await ImageKnife.getInstance().preLoadCache(url)
console.log("preload-fileCachePath=="+ fileCachePath) console.log("preload-fileCachePath=="+ fileCachePath)
} }
async preload1(url:string) { async preload1(url:string) {
let fileCachePath = await ImageKnife.getInstance().preLoadCache({ loadSrc: url }) let fileCachePath = await ImageKnife.getInstance().preLoadCache(new ImageKnifeOption({ loadSrc: url }))
console.log("preload-fileCachePath1=="+ fileCachePath) console.log("preload-fileCachePath1=="+ fileCachePath)
} }
build() { build() {

View File

@ -15,16 +15,16 @@
import { ImageKnifeComponent, ImageKnife, ImageKnifeOption, CacheStrategy } from '@ohos/libraryimageknife' import { ImageKnifeComponent, ImageKnife, ImageKnifeOption, CacheStrategy } from '@ohos/libraryimageknife'
@Entry @Entry
@Component @ComponentV2
struct TestRemoveCache { struct TestRemoveCache {
@State imageKnifeOption: ImageKnifeOption = { @Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.startIcon'), loadSrc: $r('app.media.startIcon'),
placeholderSrc: $r('app.media.loading'), placeholderSrc: $r('app.media.loading'),
errorholderSrc:$r('app.media.failed') errorholderSrc:$r('app.media.failed')
} })
@State source: PixelMap | string | Resource = $r("app.media.startIcon"); @Local source: PixelMap | string | Resource = $r("app.media.startIcon");
@State source1: PixelMap | string | Resource = $r("app.media.startIcon"); @Local source1: PixelMap | string | Resource = $r("app.media.startIcon");
@State url: string = ''; @Local url: string = '';
build() { build() {
Column() { Column() {

View File

@ -15,12 +15,17 @@
import { ImageKnifeComponent, ImageKnife, ImageKnifeOption } from '@ohos/libraryimageknife' import { ImageKnifeComponent, ImageKnife, ImageKnifeOption } from '@ohos/libraryimageknife'
@Entry @Entry
@Component @ComponentV2
struct TestSetCustomImagePage { struct TestSetCustomImagePage {
@State imageKnifeOption: ImageKnifeOption = {
getResourceString(res:Resource){
return getContext().resourceManager.getStringSync(res.id)
}
@Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.startIcon'), loadSrc: $r('app.media.startIcon'),
placeholderSrc: $r('app.media.loading') placeholderSrc: $r('app.media.loading')
} })
aboutToAppear(): void { aboutToAppear(): void {
ImageKnife.getInstance().setCustomGetImage(custom) ImageKnife.getInstance().setCustomGetImage(custom)
} }
@ -29,23 +34,23 @@ struct TestSetCustomImagePage {
} }
build() { build() {
Column() { Column() {
Button("自定义下载a").onClick(()=>{ Button(this.getResourceString($r('app.string.Custom_network_download')) + " a").onClick(()=>{
this.imageKnifeOption = { this.imageKnifeOption = new ImageKnifeOption({
loadSrc: "aaa", loadSrc: "aaa",
placeholderSrc: $r('app.media.loading') placeholderSrc: $r('app.media.loading')
} })
}) })
Button("自定义下载b").onClick(()=>{ Button(this.getResourceString($r('app.string.Custom_network_download')) + " b").onClick(()=>{
this.imageKnifeOption = { this.imageKnifeOption = new ImageKnifeOption({
loadSrc: "bbb", loadSrc: "bbb",
placeholderSrc: $r('app.media.loading') placeholderSrc: $r('app.media.loading')
} })
}) })
Button("自定义下载c").onClick(()=>{ Button(this.getResourceString($r('app.string.Custom_network_download')) + " c").onClick(()=>{
this.imageKnifeOption = { this.imageKnifeOption = new ImageKnifeOption({
loadSrc: "ccc", loadSrc: "ccc",
placeholderSrc: $r('app.media.loading') placeholderSrc: $r('app.media.loading')
} })
}) })
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: this.imageKnifeOption imageKnifeOption: this.imageKnifeOption

View File

@ -24,12 +24,12 @@ export struct ZuImage {
if (this.src) { if (this.src) {
//当前版本存在bug //当前版本存在bug
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: new ImageKnifeOption({
loadSrc: this.src, loadSrc: this.src,
placeholderSrc: this.placeholderSrc, placeholderSrc: this.placeholderSrc,
errorholderSrc: this.errorholderSrc ?? this.placeholderSrc, errorholderSrc: this.errorholderSrc ?? this.placeholderSrc,
objectFit: ImageFit.Cover objectFit: ImageFit.Cover
} })
}) })
} else { } else {
Image(this.placeholderSrc) Image(this.placeholderSrc)
@ -44,7 +44,7 @@ export struct ZuImage {
struct TestTaskResourcePage { struct TestTaskResourcePage {
@Local stateMenus: Array<string> = [ @Local stateMenus: Array<string> = [
"https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB", "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
'https://img-blog.csdnimg.cn/20191215043500229.png', 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg',
'https://img-blog.csdn.net/20140514114029140', 'https://img-blog.csdn.net/20140514114029140',
'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp', 'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
] ]

View File

@ -15,55 +15,55 @@
import { ImageKnifeComponent,CacheStrategy,ImageKnifeOption } from '@ohos/libraryimageknife' import { ImageKnifeComponent,CacheStrategy,ImageKnifeOption } from '@ohos/libraryimageknife'
@Entry @Entry
@Component @ComponentV2
struct TestWriteCacheStage { struct TestWriteCacheStage {
@State imageKnifeOption1: ImageKnifeOption = { @Local imageKnifeOption1: ImageKnifeOption = new ImageKnifeOption({
loadSrc:$r('app.media.startIcon'), loadSrc:$r('app.media.startIcon'),
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed') errorholderSrc:$r('app.media.failed')
} })
@State imageKnifeOption2: ImageKnifeOption = { @Local imageKnifeOption2: ImageKnifeOption = new ImageKnifeOption({
loadSrc:$r('app.media.startIcon'), loadSrc:$r('app.media.startIcon'),
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed') errorholderSrc:$r('app.media.failed')
} })
@State imageKnifeOption3: ImageKnifeOption = { @Local imageKnifeOption3: ImageKnifeOption = new ImageKnifeOption({
loadSrc:$r('app.media.startIcon'), loadSrc:$r('app.media.startIcon'),
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed') errorholderSrc:$r('app.media.failed')
} })
build() { build() {
Column() { Column() {
Button("写入内存文件缓存").margin({top:10}).onClick(async ()=>{ Button($r('app.string.Write_memory_and_file')).margin({top:10}).onClick(async ()=>{
this.imageKnifeOption1 = { this.imageKnifeOption1 = new ImageKnifeOption({
loadSrc:'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp', loadSrc:'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed'), errorholderSrc:$r('app.media.failed'),
writeCacheStrategy:CacheStrategy.Default writeCacheStrategy:CacheStrategy.Default
} })
}) })
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: this.imageKnifeOption1 imageKnifeOption: this.imageKnifeOption1
}).width(200).height(200).margin({top:10}) }).width(200).height(200).margin({top:10})
Button("写入内存缓存").margin({top:10}).onClick(async ()=>{ Button($r('app.string.Write_memory')).margin({top:10}).onClick(async ()=>{
this.imageKnifeOption2 = { this.imageKnifeOption2 = new ImageKnifeOption({
loadSrc:"https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB", loadSrc:"https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed'), errorholderSrc:$r('app.media.failed'),
writeCacheStrategy:CacheStrategy.Memory writeCacheStrategy:CacheStrategy.Memory
} })
}) })
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: this.imageKnifeOption2 imageKnifeOption: this.imageKnifeOption2
}).width(200).height(200).margin({top:10}) }).width(200).height(200).margin({top:10})
Button("写入文件缓存").margin({top:10}).onClick(async ()=>{ Button($r('app.string.Write_file')).margin({top:10}).onClick(async ()=>{
this.imageKnifeOption3 = { this.imageKnifeOption3 = new ImageKnifeOption({
loadSrc:'https://img-blog.csdn.net/20140514114029140', loadSrc:'https://img-blog.csdn.net/20140514114029140',
placeholderSrc:$r('app.media.loading'), placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed'), errorholderSrc:$r('app.media.failed'),
writeCacheStrategy:CacheStrategy.File writeCacheStrategy:CacheStrategy.File
} })
}) })
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: this.imageKnifeOption3 imageKnifeOption: this.imageKnifeOption3

View File

@ -17,17 +17,17 @@ import matrix4 from '@ohos.matrix4'
@Entry @Entry
@Component @ComponentV2
struct TransformPage { struct TransformPage {
private custom_scale:number = 1 private custom_scale:number = 1
@State matrix1:object = matrix4.identity().scale({ x: 1, y: 1 }) @Local matrix1:object = matrix4.identity().scale({ x: 1, y: 1 })
@State ImageKnifeOption: ImageKnifeOption = { @Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r("app.media.rabbit"), loadSrc: $r("app.media.rabbit"),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain, objectFit: ImageFit.Contain,
border: { radius: 50 } border: { radius: 50 }
} })
build() { build() {
Column() { Column() {

View File

@ -15,24 +15,50 @@
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife' import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'
// const logger = new imUtils.logger.IMLogger('Avatar') // const logger = new imUtils.logger.IMLogger('Avatar')
@ObservedV2
class MyImageOption extends ImageKnifeOption { export class MyStorage {
account?: string static instance:MyStorage | undefined = undefined
static getInstance(){
if(MyStorage.instance == undefined) {
MyStorage.instance = new MyStorage()
}
return MyStorage.instance
}
@Trace WeLink_Mob_fontSize_multiple: number = 1
} }
@Component @ComponentV2
export struct UserAvatar { export struct UserAvatar {
@Prop @Watch('userInfoUpdate') userInfo: string = ""
// @Prop userInfo: string = "" // @Prop userInfo: string = ""
imgSize: number = 100 imgSize: number = 100
radius: number = 12 radius: number = 12
borderSize: number = 0 borderSize: number = 0
imgSizes: number = 1 imgSizes: number = 1
@State ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption() @Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption()
@StorageProp('WeLink_Mob_fontSize_multiple') @Watch('updateImgSize') WeLink_Mob_fontSize_multiple: number = 0
scalable: boolean = true; scalable: boolean = true;
@State calcImgSize: number = 100 @Local calcImgSize: number = 100
@Param userInfo: string = ""
@Monitor('userInfo')
userInfoUpdate() {
// if (uri === 'userInfo' && this.imageKnifeOption.account !== this.userInfo.contactId) return;
// // logger.info(`userInfoUpdate uri=${uri} oldAcc=${this.imageKnifeOption.loadSrc} nowAcc=${this.userInfo.externalHeadUrl}`)
// if (this.userInfo.externalHeadUrl === this.imageKnifeOption.loadSrc && this.userInfo.infoUpdateTime.getTime()
// .toString() === this.imageKnifeOption?.signature?.getKey()) return;
this.ImageKnifeOption = new ImageKnifeOption({
//TODO:写死loadSRC场景变更组件大小所有图片不显示
loadSrc: this.userInfo,
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
border: { radius:20,width:5,color:$r('app.color.start_window_background') },
objectFit:ImageFit.Contain
// signature: new ObjectKey(this.userInfo.infoUpdateTime.getTime().toString())
})
}
@Local storage: MyStorage = MyStorage.getInstance()
@Monitor('storage.WeLink_Mob_fontSize_multiple')
updateImgSize() {
this.setImageSize()
}
aboutToAppear(): void { aboutToAppear(): void {
this.userInfoUpdate() this.userInfoUpdate()
this.setImageSize() this.setImageSize()
@ -41,39 +67,19 @@ export struct UserAvatar {
setImageSize() { setImageSize() {
if (!this.scalable) { if (!this.scalable) {
this.calcImgSize = this.imgSize this.calcImgSize = this.imgSize
} else if (this.WeLink_Mob_fontSize_multiple < 0.9) { } else if (this.storage.WeLink_Mob_fontSize_multiple < 0.9) {
this.calcImgSize = this.imgSize * 0.9 this.calcImgSize = this.imgSize * 0.9
} else if (this.WeLink_Mob_fontSize_multiple > 1.6) { } else if (this.storage.WeLink_Mob_fontSize_multiple > 1.6) {
this.calcImgSize = this.imgSize * 1.6 this.calcImgSize = this.imgSize * 1.6
} else { } else {
this.calcImgSize = this.imgSize * this.WeLink_Mob_fontSize_multiple this.calcImgSize = this.imgSize * this.storage.WeLink_Mob_fontSize_multiple
} }
} }
updateImgSize() {
this.setImageSize()
}
aboutToReuse(param: ESObject) { aboutToReuse(param: ESObject) {
this.userInfoUpdate() this.userInfoUpdate()
} }
userInfoUpdate() {
// if (uri === 'userInfo' && this.imageKnifeOption.account !== this.userInfo.contactId) return;
// // logger.info(`userInfoUpdate uri=${uri} oldAcc=${this.imageKnifeOption.loadSrc} nowAcc=${this.userInfo.externalHeadUrl}`)
// if (this.userInfo.externalHeadUrl === this.imageKnifeOption.loadSrc && this.userInfo.infoUpdateTime.getTime()
// .toString() === this.imageKnifeOption?.signature?.getKey()) return;
this.ImageKnifeOption = {
//TODO:写死loadSRC场景变更组件大小所有图片不显示
loadSrc: this.userInfo,
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
border: { radius:20,width:5,color:$r('app.color.start_window_background') },
objectFit:ImageFit.Contain
// signature: new ObjectKey(this.userInfo.infoUpdateTime.getTime().toString())
}
}
build() { build() {
Row() { Row() {
// Image(this.imageKnifeOption.loadSrc) // Image(this.imageKnifeOption.loadSrc)

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { UserAvatar } from './User' import { MyStorage, UserAvatar } from './User'
class CommonDataSource <T> implements IDataSource { class CommonDataSource <T> implements IDataSource {
private dataArray: T[] = [] private dataArray: T[] = []
@ -55,56 +55,72 @@ class CommonDataSource <T> implements IDataSource {
} }
} }
@Entry @Entry
@Component @ComponentV2
struct Index { struct Index {
@State hotCommendList:CommonDataSource<string> = new CommonDataSource<string>([]) @Local hotCommendList:CommonDataSource<string> = new CommonDataSource<string>([])
private data:string[] = [ private data:string[] = [
"http://e.hiphotos.baidu.com/image/pic/item/a1ec08fa513d2697e542494057fbb2fb4316d81e.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg",
"http://c.hiphotos.baidu.com/image/pic/item/30adcbef76094b36de8a2fe5a1cc7cd98d109d99.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e2/v3/4zI1Xm_3STmV30aZXWRrKw/6aN7WodDRUiBApgffiLPCg.jpg",
"http://h.hiphotos.baidu.com/image/pic/item/7c1ed21b0ef41bd5f2c2a9e953da81cb39db3d1d.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/42/v3/2dSQCqERTP2TTPyssOMEbQ/zL1ebnKKQ_ilqTDcwCAkOw.jpg",
"http://g.hiphotos.baidu.com/image/pic/item/55e736d12f2eb938d5277fd5d0628535e5dd6f4a.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/78/v3/qQJpAtRGQe2e_VhbGHDgIw/b3zlit99S6GybD3XdNwqJw.jpg",
"http://e.hiphotos.baidu.com/image/pic/item/4e4a20a4462309f7e41f5cfe760e0cf3d6cad6ee.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/55/v3/5DZ2LLqYSsK85-shqgLveQ/7ZXcyCWNTvOzQP5FFLBGkg.jpg",
"http://b.hiphotos.baidu.com/image/pic/item/9d82d158ccbf6c81b94575cfb93eb13533fa40a2.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg",
"http://e.hiphotos.baidu.com/image/pic/item/4bed2e738bd4b31c1badd5a685d6277f9e2ff81e.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/25/v3/jgB2ekkTRX-3yTYZalnANQ/xff_x9cbSPqb7fbNwgJa7A.jpg",
"http://g.hiphotos.baidu.com/image/pic/item/0d338744ebf81a4c87a3add4d52a6059252da61e.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/alXwXLHKSyCAIWt_ydgD2g/BCCuu25TREOitQxM7eYOEw.jpg",
"http://a.hiphotos.baidu.com/image/pic/item/f2deb48f8c5494ee5080c8142ff5e0fe99257e19.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/63/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg",
"http://f.hiphotos.baidu.com/image/pic/item/4034970a304e251f503521f5a586c9177e3e53f9.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/16/v3/fm2tO4TsRH6mv_D_nSSd5w/FscLpLwQQ-KuV7oaprFK2Q.jpg",
"http://b.hiphotos.baidu.com/image/pic/item/279759ee3d6d55fbb3586c0168224f4a20a4dd7e.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/89/v3/UAUvtPHqRD-GWWANsEC57Q/zcRJCQebQ322Aby4jzmwmQ.jpg",
"http://img2.xkhouse.com/bbs/hfhouse/data/attachment/forum/corebbs/2009-11/2009113011534566298.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/tUUzzx73R4yp8G--lMhuWQ/EBbcu_dLTT-Jj68XAh6mtA.jpg",
"http://a.hiphotos.baidu.com/image/pic/item/e824b899a9014c087eb617650e7b02087af4f464.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg",
"http://c.hiphotos.baidu.com/image/pic/item/9c16fdfaaf51f3de1e296fa390eef01f3b29795a.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/37/v3/12rH1yiEQmK9wlOOcy5avQ/RzBXiEBRRqOC7LRkwNj6VA.jpg",
"http://d.hiphotos.baidu.com/image/pic/item/b58f8c5494eef01f119945cbe2fe9925bc317d2a.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/9a/v3/TpRN4AIzRoyUXIqWdKoE0g/ShOnD_tfS46HDbpSWhbCkQ.jpg",
"http://h.hiphotos.baidu.com/image/pic/item/902397dda144ad340668b847d4a20cf430ad851e.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/03/v3/H3X17s8eTdS2w56JgbB5jQ/a45sT-j8Sbe8sSQXTzeYvQ.jpg",
"http://b.hiphotos.baidu.com/image/pic/item/359b033b5bb5c9ea5c0e3c23d139b6003bf3b374.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg",
"http://a.hiphotos.baidu.com/image/pic/item/8d5494eef01f3a292d2472199d25bc315d607c7c.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/96/v3/rMJJoAflTDSWa1z2pHs2wg/8dOqD0GlQBOCL5AvQok9FQ.jpg",
"http://b.hiphotos.baidu.com/image/pic/item/e824b899a9014c08878b2c4c0e7b02087af4f4a3.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg",
"http://g.hiphotos.baidu.com/image/pic/item/6d81800a19d8bc3e770bd00d868ba61ea9d345f2.jpg", "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/d9/v3/FSZH0aTdSqWxeAaxoPvi0g/RqxPxUCXQFiTMBfKTF9kkw.jpg",
"https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB", "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
'https://img-blog.csdnimg.cn/20191215043500229.png', 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg',
'https://img-blog.csdn.net/20140514114029140', 'https://img-blog.csdn.net/20140514114029140',
'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp', 'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
] ]
aboutToAppear(): void { aboutToAppear(): void {
this.hotCommendList.addData(this.hotCommendList.totalCount(),this.data) MyStorage.getInstance().WeLink_Mob_fontSize_multiple = 1
AppStorage.set("WeLink_Mob_fontSize_multiple",1)
} }
build() { build() {
Column() { Column() {
Button("bigger").onClick(()=>{ Button("bigger").onClick(()=>{
AppStorage.set("WeLink_Mob_fontSize_multiple",1.6) MyStorage.getInstance().WeLink_Mob_fontSize_multiple = 1.6
}) })
Button("small").onClick(()=>{ Button("small").onClick(()=>{
AppStorage.set("WeLink_Mob_fontSize_multiple",0.8) MyStorage.getInstance().WeLink_Mob_fontSize_multiple = 0.8
}) })
List(){ List(){
LazyForEach(this.hotCommendList,(item:string)=>{ // LazyForEach(this.hotCommendList,(item:string)=>{
ListItem(){ // ListItem(){
ReuseImage({ // ReuseImage({
userInfo:item // userInfo:item
}).width("100%").height("100%").backgroundColor(Color.Yellow) // }).width("100%").height("100%").backgroundColor(Color.Yellow)
}.width(200).height(200).margin({bottom:5}) // }.width(200).height(200).margin({bottom:5})
}) // })
Repeat(this.data)
.each((repeatItem)=>{
ListItem(){
ReuseImage({
userInfo:repeatItem.item
}).width("100%").height("100%").backgroundColor(Color.Yellow)
}.width(200).height(200).margin({bottom:5}).key("reuse")
})
.key(item => item+"reuse")
.virtualScroll()
.template("1",(repeatItem)=>{
ListItem(){
ReuseImage({
userInfo:repeatItem.item
}).width("100%").height("100%").backgroundColor(Color.Yellow)
}.width(200).height(200).margin({bottom:5}).key("reuse")
})
} }
// .cachedCount(20) // .cachedCount(20)
.width("100%") .width("100%")
@ -115,13 +131,13 @@ struct Index {
} }
@Reusable // @Reusable
@Component @ComponentV2
struct ReuseImage { struct ReuseImage {
@State userInfo:string = "" @Param userInfo:string = ""
aboutToReuse(params: ESObject): void { // aboutToReuse(params: ESObject): void {
this.userInfo = params.userInfo // this.userInfo = params.userInfo
} // }
build() { build() {
Column(){ Column(){

View File

@ -18,15 +18,15 @@ import { photoAccessHelper } from '@kit.MediaLibraryKit';
@Entry @Entry
@Component @ComponentV2
struct DataShareUriLoadPage { struct DataShareUriLoadPage {
@State imageKnifeOption1: ImageKnifeOption = @Local imageKnifeOption1: ImageKnifeOption =
{ new ImageKnifeOption({
loadSrc: $r('app.media.icon'), loadSrc: $r('app.media.icon'),
placeholderSrc: $r('app.media.loading'), placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed') errorholderSrc: $r('app.media.failed')
}; });
build() { build() {
@ -43,10 +43,10 @@ struct DataShareUriLoadPage {
let photoViewPicker = new photoAccessHelper.PhotoViewPicker(); let photoViewPicker = new photoAccessHelper.PhotoViewPicker();
let photoSelectResult: photoAccessHelper.PhotoSelectResult = await photoViewPicker.select(photoSelectOptions); let photoSelectResult: photoAccessHelper.PhotoSelectResult = await photoViewPicker.select(photoSelectOptions);
uris = photoSelectResult.photoUris; uris = photoSelectResult.photoUris;
this.imageKnifeOption1 = { this.imageKnifeOption1 = new ImageKnifeOption({
loadSrc: uris[0], loadSrc: uris[0],
placeholderSrc:$r('app.media.loading') placeholderSrc:$r('app.media.loading')
} })
}).margin({ top: 5, left: 3 }) }).margin({ top: 5, left: 3 })
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).width(300).height(300) ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).width(300).height(300)
}.width('100%').backgroundColor(Color.Pink) }.width('100%').backgroundColor(Color.Pink)

View File

@ -5,9 +5,8 @@
"description": "$string:module_desc", "description": "$string:module_desc",
"mainElement": "EntryAbility", "mainElement": "EntryAbility",
"deviceTypes": [ "deviceTypes": [
"phone", "default",
"tablet", "tablet"
"2in1"
], ],
"deliveryWithInstall": true, "deliveryWithInstall": true,
"installationFree": false, "installationFree": false,

View File

@ -367,6 +367,150 @@
{ {
"name": "TIPS", "name": "TIPS",
"value": "Please shut down the network first and ensure that there is no cache of images from this network in the test failure scenario locally" "value": "Please shut down the network first and ensure that there is no cache of images from this network in the test failure scenario locally"
},
{
"name": "Image_Downsampling_Functionality",
"value": "Downscale Image effect"
},
{
"name": "Sampling_pecification",
"value": "降采样规格"
},
{
"name": "Unreal_samples",
"value": "未降采样大小"
},
{
"name": "After_the_sampling",
"value": "降采样后大小"
},
{
"name": "image_format",
"value": "picture format%s"
},
{
"name": "image_width",
"value": "image width%d"
},
{
"name": "image_height",
"value": "image height%d"
},
{
"name": "cur_cache_limit",
"value": "%s:current cache limit%fM"
},
{
"name": "cur_cache_image_num",
"value": "%s:current cache image number%d"
},
{
"name": "cur_cache_size",
"value": "%s:current cache size%fM"
},
{
"name": "load_memory",
"value": "memory loaded picture"
},
{
"name": "load_disk",
"value": "disk cache loads images"
},
{
"name": "get_cur_memory_limit",
"value": "gets the current memory cache upper limit"
},
{
"name": "get_img_number_of_cache",
"value": "gets the number of images cached in memory"
},
{
"name": "get_cur_memory_size",
"value": "gets the size of the current cache"
},
{
"name": "get_cur_disk_limit",
"value": "Gets the current disk cache upper limit"
},
{
"name": "get_img_number_of_disk",
"value": "gets the number of images cached on disk"
},
{
"name": "get_cur_disk_size",
"value": "gets the size of the current disk"
},
{
"name": "select_color_btn",
"value": "click to select the color you want to change"
},
{
"name": "click_img_to_change_color",
"value": "click on the image to change the image color"
},
{
"name": "test_non_svg_color",
"value": "test non-SVG images for color change"
},
{
"name": "test_svg_color",
"value": "Test svg picture color change"
},
{
"name": "red",
"value": "red"
},
{
"name": "yellow",
"value": "yellow"
},
{
"name": "green",
"value": "green"
},
{
"name": "blue",
"value": "blue"
},
{
"name": "master_image",
"value": "master image:"
},
{
"name": "rm_component_of_net",
"value": "remove Component - Network load picture"
},
{
"name": "rm_component_of_local",
"value": "remove Component - Local resource picture"
},
{
"name": "component_display",
"value": "recovery component display"
},
{
"name": "onLoadCancel_reason",
"value": "onLoadCancel callback reason:%s"
},
{
"name": "test_cache_btn",
"value": "test data for in cache"
},
{
"name": "test_change_color_btn",
"value": "test change color for image"
},
{
"name": "test_cancel_callback_btn",
"value": "test callback of cancel"
},
{
"name": "memory",
"value": "Memory"
},
{
"name": "disk",
"value": "Disk"
} }
] ]
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>svg细图标</title>
<g id="细图标" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="dot_radiowaves_left_and_right" fill="#000000" fill-rule="nonzero">
<rect id="矩形" opacity="0" x="0" y="0" width="24" height="24"></rect>
<g id="编组" transform="translate(0.000000, 3.000000)" fill-opacity="0.90196079">
<path d="M12,7.01 C11.44,7.01 10.9633333,7.20666667 10.57,7.6 C10.1766667,7.98666667 9.98,8.45333333 9.98,9 C9.98,9.54666667 10.18,10.02 10.58,10.42 C10.98,10.82 11.4533333,11.02 12,11.02 C12.5466667,11.02 13.0133333,10.8233333 13.4,10.43 C13.7933333,10.0366667 13.99,9.56 13.99,9 C13.99,8.44 13.8,7.96666667 13.42,7.58 C13.0333333,7.2 12.56,7.01 12,7.01 Z" id="路径"></path>
<path d="M5.23,9 C5.23,10.1533333 5.50666667,11.2333333 6.06,12.24 C6.61333333,13.2466667 7.37666667,14.0633333 8.35,14.69 C8.53,14.8033333 8.72,14.8333333 8.92,14.78 C9.12,14.7333333 9.27333333,14.6233333 9.38,14.45 C9.49333333,14.27 9.52666667,14.08 9.48,13.88 C9.43333333,13.68 9.33,13.5266667 9.17,13.42 C8.41666667,12.92 7.82333333,12.2833333 7.39,11.51 C6.95666667,10.73 6.74,9.89333333 6.74,9 C6.74,8.10666667 6.95333333,7.26666667 7.38,6.48 C7.80666667,5.69333333 8.40333333,5.05333333 9.17,4.56 C9.34333333,4.44666667 9.45,4.29 9.49,4.09 C9.53,3.89 9.49333333,3.70333333 9.38,3.53 C9.27333333,3.35 9.12,3.23666667 8.92,3.19 C8.72,3.14333333 8.53,3.18333333 8.35,3.31 C7.37666667,3.93666667 6.61333333,4.75 6.06,5.75 C5.50666667,6.75 5.23,7.83333333 5.23,9 Z M14.59,14.45 C14.7033333,14.6233333 14.8533333,14.7333333 15.04,14.78 C15.22,14.8333333 15.4233333,14.8033333 15.65,14.69 C16.29,14.27 16.84,13.7666667 17.3,13.18 C17.7666667,12.5866667 18.1233333,11.9333333 18.37,11.22 C18.6166667,10.5066667 18.74,9.76666667 18.74,9 C18.74,7.83333333 18.47,6.75 17.93,5.75 C17.3833333,4.75 16.6233333,3.93666667 15.65,3.31 C15.47,3.18333333 15.2766667,3.14333333 15.07,3.19 C14.8633333,3.23666667 14.7033333,3.35 14.59,3.53 C14.4766667,3.70333333 14.44,3.88666667 14.48,4.08 C14.52,4.27333333 14.63,4.42666667 14.81,4.54 L14.83,4.56 C15.5833333,5.05333333 16.1766667,5.69333333 16.61,6.48 C17.0433333,7.26666667 17.26,8.10666667 17.26,9 C17.26,9.59333333 17.1633333,10.1666667 16.97,10.72 C16.7766667,11.2666667 16.4966667,11.7733333 16.13,12.24 C15.7633333,12.7066667 15.33,13.1 14.83,13.42 C14.6566667,13.5266667 14.5466667,13.68 14.5,13.88 C14.4466667,14.08 14.4766667,14.27 14.59,14.45 Z" id="形状"></path>
<path d="M0.77,9 C0.77,10.6666667 1.12,12.2466667 1.82,13.74 C2.52666667,15.2333333 3.51333333,16.5166667 4.78,17.59 C4.94,17.7166667 5.12,17.7733333 5.32,17.76 C5.52,17.7466667 5.69,17.6666667 5.83,17.52 C5.95666667,17.36 6.01333333,17.1766667 6,16.97 C5.98666667,16.7633333 5.9,16.5866667 5.74,16.44 C4.63333333,15.5133333 3.77666667,14.4 3.17,13.1 C2.56333333,11.8066667 2.26,10.44 2.26,9 C2.26,7.56 2.56333333,6.18666667 3.17,4.88 C3.77666667,3.58 4.64,2.46666667 5.76,1.54 C5.90666667,1.39333333 5.99,1.21666667 6.01,1.01 C6.03666667,0.803333333 5.97666667,0.626666667 5.83,0.48 C5.70333333,0.32 5.53666667,0.233333333 5.33,0.22 C5.12333333,0.2 4.94,0.253333333 4.78,0.38 C3.51333333,1.45333333 2.52666667,2.74333333 1.82,4.25 C1.12,5.75 0.77,7.33333333 0.77,9 Z M18.17,17.5 C18.2966667,17.66 18.4633333,17.7466667 18.67,17.76 C18.8766667,17.7733333 19.06,17.7166667 19.22,17.59 C20.0733333,16.89 20.8,16.0833333 21.4,15.17 C22,14.2566667 22.4533333,13.2766667 22.76,12.23 C23.0733333,11.1833333 23.23,10.1066667 23.23,9 C23.23,7.89333333 23.0733333,6.81666667 22.76,5.77 C22.4533333,4.72333333 22,3.74 21.4,2.82 C20.8,1.9 20.0733333,1.08666667 19.22,0.38 C19.06,0.253333333 18.8766667,0.2 18.67,0.22 C18.4633333,0.233333333 18.2966667,0.32 18.17,0.48 C18.0233333,0.64 17.96,0.823333333 17.98,1.03 C17.9933333,1.23666667 18.08,1.40666667 18.24,1.54 C18.9733333,2.14666667 19.6,2.85 20.12,3.65 C20.64,4.45 21.0366667,5.3 21.31,6.2 C21.5833333,7.10666667 21.72,8.04 21.72,9 C21.72,9.96 21.5833333,10.8933333 21.31,11.8 C21.0366667,12.7 20.6466667,13.5466667 20.14,14.34 C19.6266667,15.1333333 19,15.8333333 18.26,16.44 C18.1,16.5666667 18.0133333,16.7333333 18,16.94 C17.9866667,17.1533333 18.0433333,17.34 18.17,17.5 Z" id="形状"></path>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -3,7 +3,6 @@
"pages/Index", "pages/Index",
"pages/ListPage", "pages/ListPage",
"pages/SingleImage", "pages/SingleImage",
"pages/ManyPhotoShowPage",
"pages/LongImagePage", "pages/LongImagePage",
"pages/TransformPage", "pages/TransformPage",
"pages/UserPage", "pages/UserPage",
@ -23,6 +22,10 @@
"pages/ImageAnimatorPage", "pages/ImageAnimatorPage",
"pages/TestSetCustomImagePage", "pages/TestSetCustomImagePage",
"pages/TestErrorHolderPage", "pages/TestErrorHolderPage",
"pages/TestTaskResourcePage" "pages/TestTaskResourcePage",
"pages/DownSamplePage",
"pages/TestCacheDataPage",
"pages/TestChangeColorPage",
"pages/TestLoadCancelListenerPage"
] ]
} }

View File

@ -363,6 +363,150 @@
{ {
"name": "TIPS", "name": "TIPS",
"value": "测试失败场景请先关闭网络,并保证本地没有此网络图片的缓存" "value": "测试失败场景请先关闭网络,并保证本地没有此网络图片的缓存"
},
{
"name": "Image_Downsampling_Functionality",
"value": "降采样功能"
},
{
"name": "Sampling_pecification",
"value": "降采样规格"
},
{
"name": "Unreal_samples",
"value": "未降采样大小"
},
{
"name": "After_the_sampling",
"value": "降采样后大小"
},
{
"name": "image_format",
"value": "图片格式:%s"
},
{
"name": "image_width",
"value": "图片宽度:%d"
},
{
"name": "image_height",
"value": "图片高度:%d"
},
{
"name": "cur_cache_limit",
"value": "%s:当前缓存上限:%fM"
},
{
"name": "cur_cache_image_num",
"value": "%s:当前缓存图片数量:%d"
},
{
"name": "cur_cache_size",
"value": "%s:当前缓存的大小:%fM"
},
{
"name": "load_memory",
"value": "内存加载图片"
},
{
"name": "load_disk",
"value": "磁盘缓存加载图片"
},
{
"name": "get_cur_memory_limit",
"value": "获取当前内存缓存上限"
},
{
"name": "get_img_number_of_cache",
"value": "获取当前内存缓存图片数量"
},
{
"name": "get_cur_memory_size",
"value": "获取当前缓存的大小"
},
{
"name": "get_cur_disk_limit",
"value": "获取当前磁盘缓存上限"
},
{
"name": "get_img_number_of_disk",
"value": "获取当前磁盘缓存图片数量"
},
{
"name": "get_cur_disk_size",
"value": "获取当前磁盘的大小"
},
{
"name": "select_color_btn",
"value": "点击选择要更改的颜色"
},
{
"name": "click_img_to_change_color",
"value": "点击图片更改图片颜色"
},
{
"name": "test_non_svg_color",
"value": "测试非svg图片变色"
},
{
"name": "test_svg_color",
"value": "测试svg图片变色"
},
{
"name": "red",
"value": "红色"
},
{
"name": "yellow",
"value": "黄色"
},
{
"name": "green",
"value": "绿色"
},
{
"name": "blue",
"value": "蓝色"
},
{
"name": "master_image",
"value": "原图:"
},
{
"name": "rm_component_of_net",
"value": "移除组件-网络加载图片"
},
{
"name": "rm_component_of_local",
"value": "移除组件-本地资源图片"
},
{
"name": "component_display",
"value": "恢复组件显示"
},
{
"name": "onLoadCancel_reason",
"value": "onLoadCancel回调原因:%s"
},
{
"name": "test_cache_btn",
"value": "测试缓存数据"
},
{
"name": "test_change_color_btn",
"value": "测试颜色变换"
},
{
"name": "test_cancel_callback_btn",
"value": "测试加载取消回调接口"
},
{
"name": "memory",
"value": "内存"
},
{
"name": "disk",
"value": "磁盘"
} }
] ]
} }

View File

@ -70,10 +70,10 @@ export default function DefaultJobQueueTest() {
} }
function makeRequest(src: string, context: common.UIAbilityContext, priority?: taskpool.Priority): ImageKnifeRequest { function makeRequest(src: string, context: common.UIAbilityContext, priority?: taskpool.Priority): ImageKnifeRequest {
let option: ImageKnifeOption = { let option: ImageKnifeOption = new ImageKnifeOption({
loadSrc: src, loadSrc: src,
priority: priority priority: priority
} })
return new ImageKnifeRequest( return new ImageKnifeRequest(
option, option,
context, context,

View File

@ -153,9 +153,9 @@ export default function FileLruCacheTest() {
}); });
it('fileCacheEngineKey', 0, () => { it('fileCacheEngineKey', 0, () => {
let engineKey: IEngineKey = new DefaultEngineKey() let engineKey: IEngineKey = new DefaultEngineKey()
let imageKnifeOption: ImageKnifeOption = { let imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc:"abc" loadSrc:"abc"
} })
let imageKey = engineKey.generateFileKey(imageKnifeOption.loadSrc,"") let imageKey = engineKey.generateFileKey(imageKnifeOption.loadSrc,"")
let imageAnimatorKey = engineKey.generateFileKey(imageKnifeOption.loadSrc,"",true) let imageAnimatorKey = engineKey.generateFileKey(imageKnifeOption.loadSrc,"",true)
expect(imageKey == imageAnimatorKey).assertFalse() expect(imageKey == imageAnimatorKey).assertFalse()

View File

@ -40,10 +40,10 @@ export default function ImageKnifeTest() {
it('removeMemoryCache', 0, async () => { it('removeMemoryCache', 0, async () => {
let a = 'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp'; let a = 'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp';
let option: ImageKnifeOption = { let option: ImageKnifeOption = new ImageKnifeOption({
loadSrc: 'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp', loadSrc: 'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
signature: '' signature: ''
} })
let key = ImageKnife.getInstance() let key = ImageKnife.getInstance()
.getEngineKeyImpl() .getEngineKeyImpl()
.generateMemoryKey('https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp', ImageKnifeRequestSource.SRC, option) .generateMemoryKey('https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp', ImageKnifeRequestSource.SRC, option)

View File

@ -44,7 +44,7 @@ export default function ImageKnifeOptionTest() {
imageWidth: 0, imageWidth: 0,
imageHeight: 0, imageHeight: 0,
} }
let ImageKnifeOption: ImageKnifeOption = { let imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r("app.media.rabbit"), loadSrc: $r("app.media.rabbit"),
onLoadListener: { onLoadListener: {
onLoadFailed: (err) => { onLoadFailed: (err) => {
@ -58,10 +58,10 @@ export default function ImageKnifeOptionTest() {
return data; return data;
}, },
}, },
} })
if (ImageKnifeOption.onLoadListener && ImageKnifeOption.onLoadListener.onLoadSuccess && ImageKnifeOption.onLoadListener.onLoadFailed) { if (imageKnifeOption.onLoadListener && imageKnifeOption.onLoadListener.onLoadSuccess && imageKnifeOption.onLoadListener.onLoadFailed) {
ImageKnifeOption.onLoadListener.onLoadSuccess(a,imageData); imageKnifeOption.onLoadListener.onLoadSuccess(a,imageData);
ImageKnifeOption.onLoadListener.onLoadFailed(a); imageKnifeOption.onLoadListener.onLoadFailed(a);
} }
expect(a).assertEqual(b); expect(a).assertEqual(b);
}); });

View File

@ -18,6 +18,8 @@ import ImageKnifeOptionTest from './ImageKnifeOption.test';
import MemoryLruCacheTest from './MemoryLruCache.test'; import MemoryLruCacheTest from './MemoryLruCache.test';
import ImageKnifeTest from './ImageKnife.test'; import ImageKnifeTest from './ImageKnife.test';
import Transform from './transform.test'; import Transform from './transform.test';
import SamplingTest from './SamplingTest.test';
import imageFormatAndSize from './imageFormatAndSize.test'
export default function testsuite() { export default function testsuite() {
MemoryLruCacheTest(); MemoryLruCacheTest();
@ -26,4 +28,6 @@ export default function testsuite() {
ImageKnifeOptionTest(); ImageKnifeOptionTest();
ImageKnifeTest(); ImageKnifeTest();
Transform(); Transform();
SamplingTest()
imageFormatAndSize();
} }

View File

@ -122,9 +122,9 @@ export default function MemoryLruCacheTest() {
it('memoryCacheEngineKey', 0, () => { it('memoryCacheEngineKey', 0, () => {
let engineKey: IEngineKey = new DefaultEngineKey() let engineKey: IEngineKey = new DefaultEngineKey()
let imageKnifeOption: ImageKnifeOption = { let imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc:"abc" loadSrc:"abc"
} })
let imageKey = engineKey.generateMemoryKey(imageKnifeOption.loadSrc,ImageKnifeRequestSource.SRC,imageKnifeOption) let imageKey = engineKey.generateMemoryKey(imageKnifeOption.loadSrc,ImageKnifeRequestSource.SRC,imageKnifeOption)
let imageAnimatorKey = engineKey.generateMemoryKey(imageKnifeOption.loadSrc,ImageKnifeRequestSource.SRC,imageKnifeOption,true) let imageAnimatorKey = engineKey.generateMemoryKey(imageKnifeOption.loadSrc,ImageKnifeRequestSource.SRC,imageKnifeOption,true)
expect(imageKey == imageAnimatorKey).assertFalse() expect(imageKey == imageAnimatorKey).assertFalse()

View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import { image } from '@kit.ImageKit'
import { BusinessError } from '@kit.BasicServicesKit'
import { calculateScaleType, Downsampler } from '@ohos/imageknife/src/main/ets/downsampling/Downsampler'
import { DownsampleStrategy } from '@ohos/imageknife'
export default function SamplingTest() {
describe('SamplingTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
})
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
})
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
})
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
it('NONE', 0, () => {
let reqSize: calculateScaleType =
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
200, DownsampleStrategy.NONE,)
let req = (reqSize.targetWidth == 1024 && reqSize.targetHeight == 1024)
expect(req).assertEqual(true);
})
it('AT_MOST', 1, () => {
let reqSize: calculateScaleType =
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
200, DownsampleStrategy.AT_MOST)
let req = (reqSize.targetWidth < 1024 && reqSize.targetHeight < 1024)
expect(req).assertEqual(true);
})
it('FIT_CENTER', 2, () => {
let reqSize: calculateScaleType =
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
200, DownsampleStrategy.FIT_CENTER_MEMORY)
let req = (reqSize.targetWidth < 1024 && reqSize.targetHeight < 1024)
expect(req).assertEqual(true);
})
it('CENTER_OUTSIDE', 3, () => {
let reqSize: calculateScaleType =
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
200, DownsampleStrategy.CENTER_OUTSIDE_MEMORY)
let req = (reqSize.targetWidth < 1024 && reqSize.targetHeight < 1024)
expect(req).assertEqual(true);
})
it('AT_LEAST', 4, () => {
let reqSize: calculateScaleType =
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
200, DownsampleStrategy.AT_LEAST)
let req = (reqSize.targetWidth < 1024 && reqSize.targetHeight < 1024)
expect(req).assertEqual(true);
})
})
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import { SendableData } from '@ohos/imageknife/src/main/ets/components/imageknife/SendableData'
export default function SendableDataTest() {
describe('SendableDataTest', ()=> {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll( ()=> {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
})
beforeEach( ()=> {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
})
afterEach( ()=> {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
})
afterAll( ()=> {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
it('TestPlaceHolderCacheKey', 0, () => {
let value: string = "placeholderRegisterCacheKey";
let data: SendableData = new SendableData();
data.setPlaceHolderRegisterCacheKey(value);
expect(data.getPlaceHolderRegisterCacheKey()).assertEqual(value);
})
it('TestPlaceHolderMemoryCacheKey', 1, () => {
let value: string = "placeholderRegisterMemoryCacheKey";
let data: SendableData = new SendableData();
data.setPlaceHolderRegisterMemoryCacheKey(value);
expect(data.getPlaceHolderRegisterMemoryCacheKey()).assertEqual(value);
})
})
}

View File

@ -0,0 +1,106 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import { DownloadClient } from '@ohos/imageknife/src/main/ets/components/imageknife/networkmanage/DownloadClient';
import common from '@ohos.app.ability.common';
import { GlobalContext } from '../testability/GlobalContext';
import { CustomDataFetchClient, DataFetchResult, ImageKnifeGlobal, RequestOption } from '@ohos/imageknife';
const BASE_COUNT: number = 2000;
export default function CustomDataFetchClientTest() {
describe('CustomDataFetchClientTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
})
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
})
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
})
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
it('TestIsLocalLoadSrc', 0, () => {
let path = 'invalid path';
let client = new DownloadClient()
expect(client.isLocalLoadSrc(undefined, path)).assertFalse();
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
if (context != undefined) {
let loadSrc1 = (context as common.UIAbilityContext).filesDir + 'a.jpg';
let loadSrc2 = (context as common.UIAbilityContext).cacheDir + 'b.jpg';
expect(client.isLocalLoadSrc(context, loadSrc1)).assertTrue();
expect(client.isLocalLoadSrc(context, loadSrc2)).assertTrue();
}
})
it('TestLoadData', 1, async () => {
let client = new CustomDataFetchClient();
let request = new RequestOption();
request.loadSrc = $r('app.media.icon');
let error = (await client.loadData(request) as DataFetchResult).error as String;
expect(error).assertEqual('CustomDataFetchClient request or loadSrc error.');
})
it('TestLoadData_customGetImage', 2, async () => {
let client = new CustomDataFetchClient();
let request = new RequestOption();
request.loadSrc = 'http://e.hiphotos.baidu.com/image/pic/item/4e4a20a4462309f7e41f5cfe760e0cf3d6cad6ee.jpg';
request.customGetImage = (context: Context, src: string) => {
// 这里是模拟的customGetImage逻辑
return Promise.resolve(new DataFetchResult());
}
console.log('LXH', 'TestLoadData 2 --1 customGetImage is undefined ?' + (request.customGetImage == undefined));
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
let result = await client.loadData(request);
if (context != undefined) {
console.log('LXH', 'TestLoadData 2 --2');
expect(typeof result)
.assertEqual(typeof (await request?.customGetImage(context as common.UIAbilityContext, request.loadSrc)));
}
})
it('TestLoadData_combineArrayBuffers', 3, () => {
// 创建几个ArrayBuffer作为测试数据
const arrayBuffer1 = new ArrayBuffer(4);
const uint8Array1 = new Uint8Array(arrayBuffer1);
uint8Array1[0] = 1;
uint8Array1[1] = 2;
uint8Array1[2] = 3;
uint8Array1[3] = 4;
const arrayBuffer2 = new ArrayBuffer(2);
const uint8Array2 = new Uint8Array(arrayBuffer2);
uint8Array2[0] = 5;
uint8Array2[1] = 6;
let client = new CustomDataFetchClient();
const combinedArrayBuffer = client.combineArrayBuffers([arrayBuffer1, arrayBuffer2]);
expect(combinedArrayBuffer.byteLength).assertEqual(6);
const combinedUint8Array = new Uint8Array(combinedArrayBuffer);
for (let i = 0; i < 4; i++) {
expect(combinedUint8Array[i]).assertEqual(uint8Array1[i]);
}
for (let i = 0; i < 2; i++) {
expect(combinedUint8Array[i + 4]).assertEqual(uint8Array2[i]);
}
});
})
}

View File

@ -0,0 +1,89 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import {
ImageKnifeOption,
ImageKnife,
ImageKnifeRequest,
ImageKnifeRequestSource,
CacheStrategy
} from "@ohos/imageknife"
import { common } from '@kit.AbilityKit';
export default function imageFormatAndSize() {
describe('imageFormatAndSize', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
});
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
});
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
});
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
});
it('getImageSizeInCache', 0, async () => {
let width = 0;
let height = 0;
let imageFormat: string = "";
let url: string =
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg"
let imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: url,
})
await new Promise<string>((resolve, reject) => {
imageKnifeOption.onLoadListener = {
onLoadSuccess: (data, imageknifeData) => {
resolve("")
},
onLoadFailed(err) {
reject(err)
}
}
let request = new ImageKnifeRequest(
imageKnifeOption,
imageKnifeOption.context !== undefined ? imageKnifeOption.context : getContext() as common.UIAbilityContext,
0,
0,
0,
{
showPixelMap(version: number, pixelMap: PixelMap | string) {
}
}
)
ImageKnife.getInstance().execute(request);
})
let data = await ImageKnife.getInstance()
.getCacheImage(url, CacheStrategy.Memory);
if (data) {
width = data.imageWidth
height = data.imageHeight
imageFormat = data.type!
}
expect(width != 0).assertTrue();
expect(height != 0).assertTrue();
expect(imageFormat != "").assertTrue();
});
});
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import { ImageKnifeOption,ImageKnifeData } from "@ohos/imageknife"
export default function ImageKnifeOptionTest() {
describe('ImageKnifeOptionTest',() => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
});
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
});
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
});
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
});
it('onLoadListener', 0, () => {
let a = 'abc';
let b: string = '';
let imageData:ImageKnifeData = {
source: "",
imageWidth: 0,
imageHeight: 0,
}
let imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r("app.media.rabbit"),
onLoadListener: {
onLoadFailed: (err) => {
console.error("Load Failed Reason: " + err);
},
onLoadSuccess: (data,imageknifeData) => {
if(typeof data == 'string') {
return b = data;
}
imageData = imageknifeData
return data;
},
},
})
if (imageKnifeOption.onLoadListener && imageKnifeOption.onLoadListener.onLoadSuccess && imageKnifeOption.onLoadListener.onLoadFailed) {
imageKnifeOption.onLoadListener.onLoadSuccess(a,imageData);
imageKnifeOption.onLoadListener.onLoadFailed(a);
}
expect(a).assertEqual(b);
});
});
}

View File

@ -5,9 +5,8 @@
"description": "$string:module_test_desc", "description": "$string:module_test_desc",
"mainElement": "TestAbility", "mainElement": "TestAbility",
"deviceTypes": [ "deviceTypes": [
"phone", "default",
"tablet", "tablet"
"2in1"
], ],
"deliveryWithInstall": true, "deliveryWithInstall": true,
"installationFree": false, "installationFree": false,

View File

@ -1,7 +1,11 @@
## 1.0.3 ## 1.0.4
- 修改门禁编译问题 修改点如下 - 修改门禁编译问题 修改点如下
- 修改src/main/cpp/boundscheck/CMakeLists.txt文件中的内容
- 修改src/main/cpp/util/DebugLog.h文件中hilog的大小写 - 修改src/main/cpp/util/DebugLog.h文件中hilog的大小写
## 1.0.3
- 安全编译开启Strip和Ftrapv
## 1.0.2 ## 1.0.2
- 支持x86编译 - 支持x86编译

View File

@ -3,7 +3,7 @@
"buildOption": { "buildOption": {
"externalNativeOptions": { "externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt", "path": "./src/main/cpp/CMakeLists.txt",
"arguments": "", "arguments": " -DCMAKE_BUILD_TYPE=Release",
"abiFilters": [ "abiFilters": [
"armeabi-v7a", "armeabi-v7a",
"arm64-v8a", "arm64-v8a",

View File

@ -14,7 +14,7 @@
"main": "index.ets", "main": "index.ets",
"repository": "https://gitee.com/openharmony-tpc/ImageKnife", "repository": "https://gitee.com/openharmony-tpc/ImageKnife",
"type": "module", "type": "module",
"version": "1.0.3", "version": "1.0.4",
"tags": [ "tags": [
"Tool" "Tool"
], ],

View File

@ -11,8 +11,11 @@ include_directories(${NATIVERENDER_ROOT_PATH}
${NATIVERENDER_ROOT_PATH}/common ${NATIVERENDER_ROOT_PATH}/common
${NATIVERENDER_ROOT_PATH}/render ${NATIVERENDER_ROOT_PATH}/render
${NATIVERENDER_ROOT_PATH}/constant ${NATIVERENDER_ROOT_PATH}/constant
${NATIVERENDER_ROOT_PATH}/boundscheck
) )
add_subdirectory(boundscheck)
add_library(nativeGpu SHARED add_library(nativeGpu SHARED
${NATIVERENDER_ROOT_PATH}/napi/napi_init.cpp ${NATIVERENDER_ROOT_PATH}/napi/napi_init.cpp
${NATIVERENDER_ROOT_PATH}/render/EGLRender.cpp ${NATIVERENDER_ROOT_PATH}/render/EGLRender.cpp
@ -30,4 +33,4 @@ find_library (
GLES-lib GLES-lib
GLESv3 ) GLESv3 )
target_link_libraries(nativeGpu PUBLIC ${hilog-lib} ${EGL-lib} ${GLES-lib} libace_napi.z.so libc++.a) target_link_libraries(nativeGpu PUBLIC boundscheck ${hilog-lib} ${EGL-lib} ${GLES-lib} libace_napi.z.so -s -ftrapv)

View File

@ -0,0 +1,27 @@
# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)
set(can_use_assembler TRUE)
enable_language(ASM)
IF("${OHOS_ARCH}" STREQUAL "arm64-v8a")
SET(ASM_OPTIONS "-x assembler-with-cpp")
SET(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS} -march=armv8+crypto -D__OHOS__")
ENDIF()
project(boundscheck)
set(TAGET_BOUNDSCHECK_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/third_party_bounds_checking_function/src)
add_library(boundscheck
STATIC
${TAGET_BOUNDSCHECK_SRC_PATH}/memcpy_s.c
${TAGET_BOUNDSCHECK_SRC_PATH}/memset_s.c
${TAGET_BOUNDSCHECK_SRC_PATH}/securecutil.c)
target_precompile_headers(boundscheck PUBLIC ${CMAKE_SYSROOT}/usr/include/stdint.h)
include_directories(${TAGET_BOUNDSCHECK_SRC_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/third_party_bounds_checking_function/include
)
target_link_libraries(boundscheck)

@ -0,0 +1 @@
Subproject commit a45b3aceed2c0138babc951850445d1cd010ce48

View File

@ -535,7 +535,10 @@ void EGLRender::SetImageData(uint8_t *pData, int width, int height)
m_RenderImage.height = height; m_RenderImage.height = height;
m_RenderImage.format = IMAGE_FORMAT_RGBA; m_RenderImage.format = IMAGE_FORMAT_RGBA;
NativeImageUtil::AllocNativeImage(&m_RenderImage); NativeImageUtil::AllocNativeImage(&m_RenderImage);
memcpy(m_RenderImage.ppPlane[0], pData, width * height * DEFAULT_FOUR); if (memcpy_s(m_RenderImage.ppPlane[0],
width * height * DEFAULT_FOUR, pData, width * height * DEFAULT_FOUR) != EOK) {
return;
}
glBindTexture(GL_TEXTURE_2D, m_ImageTextureId); glBindTexture(GL_TEXTURE_2D, m_ImageTextureId);
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,

View File

@ -26,6 +26,7 @@
#include <string> #include <string>
#include <string.h> #include <string.h>
#include "DebugLog.h" #include "DebugLog.h"
#include "third_party_bounds_checking_function/include/securec.h"
const int32_t MAX_STR_LENGTH = 1024; const int32_t MAX_STR_LENGTH = 1024;
@ -41,7 +42,7 @@ void NapiUtil::JsValueToString(const napi_env &env, const napi_value &value, con
LOGI("%s nullptr js object to string malloc failed", __func__); LOGI("%s nullptr js object to string malloc failed", __func__);
return; return;
} }
(void) memset(buf.get(), 0, bufLen); (void) memset_s(buf.get(), bufLen, 0, bufLen);
size_t result = 0; size_t result = 0;
napi_get_value_string_utf8(env, value, buf.get(), bufLen, &result); napi_get_value_string_utf8(env, value, buf.get(), bufLen, &result);
target = buf.get(); target = buf.get();

View File

@ -30,6 +30,7 @@
#include <string.h> #include <string.h>
#include "DebugLog.h" #include "DebugLog.h"
#include "constant/constant_shape.h" #include "constant/constant_shape.h"
#include "third_party_bounds_checking_function/include/securec.h"
#define IMAGE_FORMAT_RGBA 0x01 #define IMAGE_FORMAT_RGBA 0x01
#define IMAGE_FORMAT_NV21 0x02 #define IMAGE_FORMAT_NV21 0x02
@ -48,7 +49,7 @@
#define IMAGE_FORMAT_GRAY_EXT "GRAY" #define IMAGE_FORMAT_GRAY_EXT "GRAY"
#define IMAGE_FORMAT_I444_EXT "I444" #define IMAGE_FORMAT_I444_EXT "I444"
#define IMAGE_FORMAT_P010_EXT "P010" // 16bit NV21 #define IMAGE_FORMAT_P010_EXT "P010" // 16bit NV21
#define EOK 0
struct NativeImage { struct NativeImage {
int width; int width;
@ -140,7 +141,9 @@ public:
if (napi_create_arraybuffer(env, srcLen, &nativePtr, res) != napi_ok || nativePtr == nullptr) { if (napi_create_arraybuffer(env, srcLen, &nativePtr, res) != napi_ok || nativePtr == nullptr) {
return false; return false;
} }
memcpy(nativePtr, src, srcLen); if (memcpy_s(nativePtr, srcLen, src, srcLen) != EOK) {
return false;
}
return true; return true;
} }
@ -149,10 +152,17 @@ public:
int totalLength = width * height * DEFAULT_FOUR; int totalLength = width * height * DEFAULT_FOUR;
int oneLineLength = width * DEFAULT_FOUR; int oneLineLength = width * DEFAULT_FOUR;
uint8_t* tmp = (uint8_t*)malloc(totalLength); uint8_t* tmp = (uint8_t*)malloc(totalLength);
memcpy(tmp, *buf, totalLength); if (memcpy_s(tmp, totalLength, *buf, totalLength) != EOK) {
memset(*buf, DEFAULT_ZERO, sizeof(uint8_t)*totalLength); return;
}
if (memset_s(*buf, sizeof(uint8_t)*totalLength, DEFAULT_ZERO, sizeof(uint8_t)*totalLength) != EOK) {
return;
}
for (int i = 0; i < height; i++) { for (int i = 0; i < height; i++) {
memcpy(*buf + oneLineLength * i, tmp + totalLength - oneLineLength * (i+1), oneLineLength); if (memcpy_s(*buf + oneLineLength * i, oneLineLength,
tmp + totalLength - oneLineLength * (i+1), oneLineLength) != EOK) {
break;
}
} }
free(tmp); free(tmp);
} }

View File

@ -1,6 +1,7 @@
{ {
"modelVersion": "5.0.0", "hvigorVersion": "4.0.2",
"dependencies": { "dependencies": {
"@ohos/hvigor-ohos-plugin": "4.0.2"
}, },
"execution": { "execution": {
// "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */ // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */
@ -18,4 +19,4 @@
"nodeOptions": { "nodeOptions": {
// "maxOldSpaceSize": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */ // "maxOldSpaceSize": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */
} }
} }

1
hvigor/hvigor-wrapper.js Normal file

File diff suppressed because one or more lines are too long

48
hvigorw Normal file
View File

@ -0,0 +1,48 @@
#!/bin/bash
# ----------------------------------------------------------------------------
# Hvigor startup script, version 1.0.0
#
# Required ENV vars:
# ------------------
# NODE_HOME - location of a Node home dir
# or
# Add /usr/local/nodejs/bin to the PATH environment variable
# ----------------------------------------------------------------------------
HVIGOR_APP_HOME=$(dirname $(readlink -f $0))
HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
warn() {
echo ""
echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
error() {
echo ""
echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
fail() {
error "$@"
exit 1
}
# Determine node to start hvigor wrapper script
if [ -n "${NODE_HOME}" ];then
EXECUTABLE_NODE="${NODE_HOME}/bin/node"
if [ ! -x "$EXECUTABLE_NODE" ];then
fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed"
fi
else
EXECUTABLE_NODE="node"
which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
fi
# Check hvigor wrapper script
if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
fi
# start hvigor-wrapper script
exec "${EXECUTABLE_NODE}" \
"${HVIGOR_WRAPPER_SCRIPT}" "$@"

57
hvigorw.bat Normal file
View File

@ -0,0 +1,57 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Hvigor startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js
set NODE_EXE=node.exe
goto start
:start
@rem Find node.exe
if defined NODE_HOME goto findNodeFromNodeHome
%NODE_EXE% --version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:findNodeFromNodeHome
set NODE_HOME=%NODE_HOME:"=%
set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE%
if exist "%NODE_EXE_PATH%" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:execute
@rem Execute hvigor
"%NODE_EXE%" %WRAPPER_MODULE_PATH% %*
:fail
exit /b 1

View File

@ -66,4 +66,6 @@ export { CropTransformation } from './src/main/ets/transform/CropTransformation'
export { MaskTransformation } from './src/main/ets/transform/MaskTransformation' export { MaskTransformation } from './src/main/ets/transform/MaskTransformation'
export { SepiaTransformation } from './src/main/ets/transform/SepiaTransformation' export { SepiaTransformation } from './src/main/ets/transform/SepiaTransformation'
export { DownsampleStrategy } from './src/main/ets/downsampling/DownsampleStartegy'

View File

@ -14,7 +14,7 @@
"main": "index.ets", "main": "index.ets",
"repository": "https://gitee.com/openharmony-tpc/ImageKnife", "repository": "https://gitee.com/openharmony-tpc/ImageKnife",
"type": "module", "type": "module",
"version": "3.0.2-rc.2", "version": "3.1.1-rc.0",
"dependencies": { "dependencies": {
"@ohos/gpu_transform": "^1.0.2" "@ohos/gpu_transform": "^1.0.2"
}, },

View File

@ -191,10 +191,10 @@ export class ImageKnife {
*/ */
getCacheImage(loadSrc: string, getCacheImage(loadSrc: string,
cacheType: CacheStrategy = CacheStrategy.Default, signature?: string): Promise<ImageKnifeData | undefined> { cacheType: CacheStrategy = CacheStrategy.Default, signature?: string): Promise<ImageKnifeData | undefined> {
let option: ImageKnifeOption = { let option: ImageKnifeOption = new ImageKnifeOption({
loadSrc: loadSrc, loadSrc: loadSrc,
signature:signature signature:signature
} })
let engineKeyImpl: IEngineKey = this.getEngineKeyImpl(); let engineKeyImpl: IEngineKey = this.getEngineKeyImpl();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -218,7 +218,7 @@ export class ImageKnife {
*/ */
putCacheImage(url: string, pixelMap: PixelMap, cacheType: CacheStrategy = CacheStrategy.Default, signature?: string) { putCacheImage(url: string, pixelMap: PixelMap, cacheType: CacheStrategy = CacheStrategy.Default, signature?: string) {
let memoryKey = this.getEngineKeyImpl() let memoryKey = this.getEngineKeyImpl()
.generateMemoryKey(url, ImageKnifeRequestSource.SRC, { loadSrc: url, signature: signature }); .generateMemoryKey(url, ImageKnifeRequestSource.SRC, new ImageKnifeOption({ loadSrc: url, signature: signature }));
let fileKey = this.getEngineKeyImpl().generateFileKey(url, signature); let fileKey = this.getEngineKeyImpl().generateFileKey(url, signature);
let imageKnifeData: ImageKnifeData = { source: pixelMap, imageWidth: 0, imageHeight: 0 }; let imageKnifeData: ImageKnifeData = { source: pixelMap, imageWidth: 0, imageHeight: 0 };
switch (cacheType) { switch (cacheType) {
@ -252,9 +252,9 @@ export class ImageKnife {
if (url instanceof ImageKnifeOption) { if (url instanceof ImageKnifeOption) {
imageKnifeOption = url; imageKnifeOption = url;
} else { } else {
imageKnifeOption = { imageKnifeOption = new ImageKnifeOption({
loadSrc: url loadSrc: url
}; });
} }
let key = this.getEngineKeyImpl().generateFileKey(imageKnifeOption.loadSrc, imageKnifeOption.signature); let key = this.getEngineKeyImpl().generateFileKey(imageKnifeOption.loadSrc, imageKnifeOption.signature);
if (this.fileCache !== undefined) { if (this.fileCache !== undefined) {
@ -302,6 +302,66 @@ export class ImageKnife {
return this.fileCache as FileCache return this.fileCache as FileCache
} }
/**
* get cache upper limit
* @param cacheType
* @returns
*/
getCacheUpperLimit(cacheType?: CacheStrategy): number | undefined {
if (cacheType == undefined || cacheType == CacheStrategy.Default) {
cacheType = CacheStrategy.Memory;
}
if (cacheType == CacheStrategy.Memory) {
return (this.memoryCache as MemoryLruCache).maxMemory;
} else {
if (this.isFileCacheInit()) {
return this.fileCache?.maxMemory;
} else {
throw new Error("the disk cache not init");
}
}
}
/**
* gets the number of images currently cached
* @param cacheType
* @returns
*/
getCurrentPicturesNum(cacheType: CacheStrategy): number | undefined {
if (cacheType == undefined || cacheType == CacheStrategy.Default) {
cacheType = CacheStrategy.Memory;
}
if (cacheType == CacheStrategy.Memory) {
return (this.memoryCache as MemoryLruCache).size();
} else {
if (this.isFileCacheInit()) {
return this.fileCache?.size();
} else {
throw new Error("the disk cache not init");
}
}
}
/**
* gets the current cache size
* @param cacheType
* @returns
*/
getCurrentCacheSize(cacheType: CacheStrategy): number | undefined {
if (cacheType == undefined || cacheType == CacheStrategy.Default) {
cacheType = CacheStrategy.Memory;
}
if (cacheType == CacheStrategy.Memory) {
return (this.memoryCache as MemoryLruCache).currentMemory;
} else {
if (this.isFileCacheInit()) {
return this.fileCache?.currentMemory;
} else {
throw new Error("the disk cache not init");
}
}
}
private pixelMapToArrayBuffer(pixelMap: PixelMap): ArrayBuffer { private pixelMapToArrayBuffer(pixelMap: PixelMap): ArrayBuffer {
let imageInfo = pixelMap.getImageInfoSync(); let imageInfo = pixelMap.getImageInfoSync();

View File

@ -35,6 +35,7 @@ import {
} from './model/ImageKnifeData' } from './model/ImageKnifeData'
import { BusinessError } from '@kit.BasicServicesKit'; import { BusinessError } from '@kit.BasicServicesKit';
import { ImageKnifeLoader } from './ImageKnifeLoader' import { ImageKnifeLoader } from './ImageKnifeLoader'
import { DownsampleStrategy } from './downsampling/DownsampleStartegy';
export class ImageKnifeDispatcher { export class ImageKnifeDispatcher {
@ -183,7 +184,10 @@ export class ImageKnifeDispatcher {
fileCacheFolder: ImageKnife.getInstance().getFileCache()?.getCacheFolder(), fileCacheFolder: ImageKnife.getInstance().getFileCache()?.getCacheFolder(),
isAnimator:isAnimator, isAnimator:isAnimator,
moduleName: moduleName == "" ? undefined : moduleName, moduleName: moduleName == "" ? undefined : moduleName,
resName: resName == "" ? undefined : resName resName: resName == "" ? undefined : resName,
targetWidth: currentRequest.componentWidth,
targetHeight: currentRequest.componentHeight,
downsampType: currentRequest.imageKnifeOption.downsampleOf==undefined?DownsampleStrategy.NONE:currentRequest.imageKnifeOption.downsampleOf,
} }
if(request.customGetImage == undefined) { if(request.customGetImage == undefined) {

View File

@ -28,6 +28,8 @@ import emitter from '@ohos.events.emitter';
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
import { RequestJobResult } from './model/ImageKnifeData' import { RequestJobResult } from './model/ImageKnifeData'
import util from '@ohos.util'; import util from '@ohos.util';
import { DownsampleStrategy } from './downsampling/DownsampleStartegy';
import { Downsampler } from './downsampling/Downsampler';
class RequestData { class RequestData {
receiveSize: number = 2000 receiveSize: number = 2000
@ -73,6 +75,15 @@ export class ImageKnifeLoader {
} }
let size = (await imageSource.getImageInfo()).size let size = (await imageSource.getImageInfo()).size
try {
if ((request.downsampType !== DownsampleStrategy.NONE) &&
request.requestSource == ImageKnifeRequestSource.SRC) {
decodingOptions = ImageKnifeLoader.getDownsamplerDecodingOptions(typeValue, request, size, ImageKnifeRequestSource.SRC)
}
} catch (err) {
return ImageKnifeLoader.makeEmptyResult(err)
}
await imageSource.createPixelMap(decodingOptions) await imageSource.createPixelMap(decodingOptions)
.then((pixelmap: PixelMap) => { .then((pixelmap: PixelMap) => {
resPixelmap = pixelmap resPixelmap = pixelmap
@ -110,6 +121,14 @@ export class ImageKnifeLoader {
editable: true, editable: true,
desiredSize: defaultSize desiredSize: defaultSize
}; };
try {
if ((request.downsampType !== DownsampleStrategy.NONE) &&
request.requestSource == ImageKnifeRequestSource.SRC) {
opts = ImageKnifeLoader.getDownsamplerDecodingOptions(typeValue, request, size)
}
} catch (err) {
return ImageKnifeLoader.makeEmptyResult(err)
}
await imageSource.createPixelMap(opts) await imageSource.createPixelMap(opts)
.then((pixelmap: PixelMap) => { .then((pixelmap: PixelMap) => {
resPixelmap = pixelmap resPixelmap = pixelmap
@ -354,4 +373,30 @@ export class ImageKnifeLoader {
} }
return resBuf return resBuf
} }
}
static getDownsamplerDecodingOptions(typeValue: string, request: RequestJobRequest, size: Size,
SRC?: ImageKnifeRequestSource):image.DecodingOptions {
let reqSize =
new Downsampler().calculateScaling(typeValue, size.width, size.height, request.targetWidth, request.targetHeight,
request.downsampType)
if (typeValue == "svg") {
return {
editable: true,
desiredSize: {
height: vp2px(reqSize.height),
width: vp2px(reqSize.width)
}
}
} else {
return {
editable: request.requestSource === SRC && request.transformation !== undefined ? true : false,
desiredSize:{
width: reqSize.width,
height: reqSize.height
}
}
}
}
}

View File

@ -19,15 +19,14 @@ import { ImageKnife } from '../ImageKnife';
import { LogUtil } from '../utils/LogUtil'; import { LogUtil } from '../utils/LogUtil';
import { ImageKnifeRequestSource } from '../model/ImageKnifeData'; import { ImageKnifeRequestSource } from '../model/ImageKnifeData';
@Component @ComponentV2
export struct ImageKnifeAnimatorComponent { export struct ImageKnifeAnimatorComponent {
@Watch('watchImageKnifeOption') @ObjectLink imageKnifeOption: ImageKnifeOption; @Param animatorOption: AnimatorOption = new AnimatorOption();
@State animatorOption: AnimatorOption = new AnimatorOption(); @Local pixelMap: PixelMap | string | undefined = undefined
@State pixelMap: PixelMap | string | undefined = undefined @Local imageAnimator: Array<ImageFrameInfo> | undefined = undefined
@State imageAnimator: Array<ImageFrameInfo> | undefined = undefined @Local adaptiveWidth: Length = '100%'
@State adaptiveWidth: Length = '100%' @Local adaptiveHeight: Length = '100%'
@State adaptiveHeight: Length = '100%' @Local objectFit: ImageFit = ImageFit.Contain
@State objectFit: ImageFit = ImageFit.Contain
private request: ImageKnifeRequest | undefined private request: ImageKnifeRequest | undefined
private lastWidth: number = 0 private lastWidth: number = 0
private lastHeight: number = 0 private lastHeight: number = 0
@ -35,7 +34,17 @@ export struct ImageKnifeAnimatorComponent {
private currentHeight: number = 0 private currentHeight: number = 0
private componentVersion: number = 0 private componentVersion: number = 0
private currentContext: common.UIAbilityContext | undefined = undefined private currentContext: common.UIAbilityContext | undefined = undefined
@Param imageKnifeOption: ImageKnifeOption = new ImageKnifeOption();
@Monitor('imageKnifeOption',
"imageKnifeOption.loadSrc","imageKnifeOption.signature","imageKnifeOption.transformation","imageKnifeOption.border","imageKnifeOption.objectFit")
watchImageKnifeOption() {
if (this.request !== undefined) {
this.request.requestState = ImageKnifeRequestState.DESTROY
}
this.request = undefined
this.componentVersion++
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight))
}
aboutToAppear(): void { aboutToAppear(): void {
this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit
} }
@ -86,15 +95,6 @@ export struct ImageKnifeAnimatorComponent {
.onRepeat(this.animatorOption.onRepeat) .onRepeat(this.animatorOption.onRepeat)
} }
watchImageKnifeOption() {
if (this.request !== undefined) {
this.request.requestState = ImageKnifeRequestState.DESTROY
}
this.request = undefined
this.componentVersion++
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight),true)
}
getCurrentContext(): common.UIAbilityContext { getCurrentContext(): common.UIAbilityContext {
if (this.currentContext == undefined) { if (this.currentContext == undefined) {
this.currentContext = getContext(this) as common.UIAbilityContext this.currentContext = getContext(this) as common.UIAbilityContext

View File

@ -21,14 +21,13 @@ import { ImageKnifeData, ImageKnifeRequestSource } from '../model/ImageKnifeData
import { IEngineKey } from '../key/IEngineKey'; import { IEngineKey } from '../key/IEngineKey';
import { DefaultEngineKey } from '../key/DefaultEngineKey'; import { DefaultEngineKey } from '../key/DefaultEngineKey';
@Component @ComponentV2
export struct ImageKnifeComponent { export struct ImageKnifeComponent {
@Watch('watchImageKnifeOption') @ObjectLink imageKnifeOption: ImageKnifeOption; @Local pixelMap: PixelMap | string | undefined = undefined
@State pixelMap: PixelMap | string | undefined = undefined @Param syncLoad: boolean = false
@State syncLoad: boolean = false @Local adaptiveWidth: Length = '100%'
@State adaptiveWidth: Length = '100%' @Local adaptiveHeight: Length = '100%'
@State adaptiveHeight: Length = '100%' @Local objectFit: ImageFit = ImageFit.Contain
@State objectFit: ImageFit = ImageFit.Contain
private request: ImageKnifeRequest | undefined private request: ImageKnifeRequest | undefined
private lastWidth: number = 0 private lastWidth: number = 0
private lastHeight: number = 0 private lastHeight: number = 0
@ -36,6 +35,20 @@ export struct ImageKnifeComponent {
private currentHeight: number = 0 private currentHeight: number = 0
private componentVersion: number = 0 private componentVersion: number = 0
private currentContext: common.UIAbilityContext | undefined = undefined private currentContext: common.UIAbilityContext | undefined = undefined
@Param imageKnifeOption: ImageKnifeOption = new ImageKnifeOption();
@Monitor('imageKnifeOption',
"imageKnifeOption.loadSrc","imageKnifeOption.signature","imageKnifeOption.transformation","imageKnifeOption.border","imageKnifeOption.objectFit",'imageKnifeOption.downsampleOf')
watchImageKnifeOption() {
this.clearLastRequest()
this.componentVersion++
this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit
LogUtil.log("watchImageKnifeOption execute request:width=" + this.currentWidth + " height= " + this.currentHeight
+ " loadSrc = " + this.request?.imageKnifeOption.loadSrc
+ " placeholderSrc = " + this.request?.imageKnifeOption.placeholderSrc
+ " errorholderSrc = " + this.request?.imageKnifeOption.errorholderSrc)
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight))
}
aboutToAppear(): void { aboutToAppear(): void {
this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit
@ -70,6 +83,7 @@ export struct ImageKnifeComponent {
aboutToRecycle() { aboutToRecycle() {
this.clearLastRequest() this.clearLastRequest()
} }
/** /**
* 对已DESTROY的组件不再发起请求 * 对已DESTROY的组件不再发起请求
*/ */
@ -79,6 +93,7 @@ export struct ImageKnifeComponent {
this.request = undefined this.request = undefined
} }
} }
build() { build() {
Image(this.pixelMap) Image(this.pixelMap)
.colorFilter(this.imageKnifeOption.drawingColorFilter) .colorFilter(this.imageKnifeOption.drawingColorFilter)
@ -94,29 +109,19 @@ export struct ImageKnifeComponent {
this.currentHeight = newValue.height as number this.currentHeight = newValue.height as number
this.lastWidth = oldValue.width as number this.lastWidth = oldValue.width as number
this.lastHeight = oldValue.height as number this.lastHeight = oldValue.height as number
if (this.currentWidth <= 0 || this.currentHeight <= 0) {
// 存在宽或者高为0,此次重回无意义,无需进行request请求 // 条件1: 宽高值均有效,值>0. 条件2当前宽高与上一次宽高不同
} else { if (this.currentWidth > 0 && this.currentHeight > 0 &&
// 前提:宽高值均有效,值>0. 条件1当前宽高与上一次宽高不同 条件2:当前是第一次绘制 (this.currentHeight != this.lastHeight || this.currentWidth != this.lastWidth)) {
if (this.currentHeight != this.lastHeight || this.currentWidth != this.lastWidth) { LogUtil.log("onSizeChange execute request:width=" + this.currentWidth + " height= " + this.currentHeight
LogUtil.log("execute request:width=" + this.currentWidth + " height= " + this.currentHeight) + " loadSrc = " + this.request?.imageKnifeOption.loadSrc
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight)) + " placeholderSrc = " + this.request?.imageKnifeOption.placeholderSrc
} + " errorholderSrc = " + this.request?.imageKnifeOption.errorholderSrc)
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight))
} }
}) })
} }
watchImageKnifeOption() {
this.clearLastRequest()
this.componentVersion++
this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit
LogUtil.log("watchImageKnifeOption execute request:width=" + this.currentWidth + " height= " + this.currentHeight
+ " loadSrc = " + this.request?.imageKnifeOption.loadSrc
+ " placeholderSrc = " + this.request?.imageKnifeOption.placeholderSrc
+ " errorholderSrc = " + this.request?.imageKnifeOption.errorholderSrc)
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight))
}
getCurrentContext(): common.UIAbilityContext { getCurrentContext(): common.UIAbilityContext {
if (this.currentContext == undefined) { if (this.currentContext == undefined) {
this.currentContext = getContext(this) as common.UIAbilityContext this.currentContext = getContext(this) as common.UIAbilityContext
@ -138,24 +143,10 @@ export struct ImageKnifeComponent {
return //针对reuse场景不显示历史图片 return //针对reuse场景不显示历史图片
} }
this.pixelMap = pixelMap this.pixelMap = pixelMap
if (typeof this.pixelMap !== 'string') { if (typeof this.pixelMap !== 'string' && this.imageKnifeOption.objectFit === ImageFit.Auto) { //针对静态图高度自适应
if (this.imageKnifeOption.objectFit === ImageFit.Auto) { let info = await this.pixelMap.getImageInfo()
let info = await this.pixelMap.getImageInfo() this.adaptiveWidth = this.currentWidth
this.adaptiveHeight = info.size.height * this.currentWidth / info.size.width
this.adaptiveWidth = this.currentWidth
this.adaptiveHeight = info.size.height * this.currentWidth / info.size.width
// if (this.currentWidth / this.currentHeight > info.size.width / info.size.height) {
// this.adaptiveWidth = this.currentWidth
// this.adaptiveHeight = info.size.height * this.currentWidth / this.currentHeight
// }
// else {
// this.adaptiveWidth = info.size.width * this.currentWidth / this.currentHeight
// this.adaptiveHeight = this.currentHeight
// }
}
} else {
//console.info("KKKKKKKKKKK:" + pixelMap)
} }
if (requestSource == ImageKnifeRequestSource.SRC) { if (requestSource == ImageKnifeRequestSource.SRC) {
@ -174,8 +165,4 @@ export struct ImageKnifeComponent {
return this.request return this.request
} }
}
interface KeyCanvas {
keyId: string
} }

View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DownsampleStrategy } from './DownsampleStartegy';
import { SampleSizeRounding } from './DownsampleUtils';
export interface BaseDownsampling {
getName(): string
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number,downsampType?:DownsampleStrategy): number
}

View File

@ -0,0 +1,148 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BaseDownsampling } from './BaseDownsampling';
import { getScale, highestOneBit, round, SampleSizeRounding } from './DownsampleUtils';
export class FitCenter implements BaseDownsampling {
getName() {
return "FitCenter"
}
getScaleFactor(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,
downsampType: DownsampleStrategy
): number {
//重新计算宽高比;
let outSize: Size = {
width: round(getScale(sourceWidth, sourceHeight, requestedWidth, requestedHeight, downsampType) * sourceWidth),
height:round(getScale(sourceWidth, sourceHeight, requestedWidth, requestedHeight, downsampType) * sourceHeight)
}
let scaleFactor = downsampType === DownsampleStrategy.FIT_CENTER_QUALITY?
Math.max(1, highestOneBit(Math.max(sourceWidth / outSize.width, sourceHeight / outSize.height))) :
Math.max(1, highestOneBit(Math.min(sourceWidth / outSize.width, sourceHeight / outSize.height)))//将整型的缩放因子转换为2的次幂采样大小
if (downsampType === DownsampleStrategy.FIT_CENTER_MEMORY
&& (scaleFactor < (1 / getScale(sourceWidth, sourceHeight, requestedWidth, requestedHeight, downsampType)))) {
scaleFactor = scaleFactor << 1;
}
return scaleFactor
}
}
/*宽高进行等比缩放宽高里面最小的比例先放进去
然后再更据原图的缩放比去适配另一边*/
export class AtLeast implements BaseDownsampling {
getName() {
return "AtLeast"
}
getScaleFactor(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number): number {
const widthPercentage = requestedWidth / sourceWidth;
const heightPercentage = requestedHeight / sourceHeight;
//返回宽度和高度比例中最大的值
let outSize: Size = {
width: round(Math.max(widthPercentage, heightPercentage) * sourceWidth),
height:round(Math.max(widthPercentage, heightPercentage) * sourceHeight)
}
let scaleFactor = Math.max(1, highestOneBit(Math.max(sourceWidth / outSize.width, sourceHeight / outSize.height)))
return scaleFactor
}
}
/*请求尺寸大于实际尺寸不进行放大,按照原图展示*/
export class AtMost implements BaseDownsampling {
getName() {
return "AtMost"
}
getScaleFactor(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number): number {
const maxIntegerFactor = Math.ceil(Math.max(sourceHeight / requestedHeight, sourceWidth / requestedWidth));
let lesserOrEqualSampleSize = Math.max(1, highestOneBit(maxIntegerFactor));
let greaterOrEqualSampleSize = lesserOrEqualSampleSize
if (lesserOrEqualSampleSize < maxIntegerFactor) {
greaterOrEqualSampleSize = lesserOrEqualSampleSize <<= 1;
}
greaterOrEqualSampleSize = lesserOrEqualSampleSize << (lesserOrEqualSampleSize < maxIntegerFactor ? 1 : 0)
let outSize: Size = {
width: round((1 / greaterOrEqualSampleSize) * sourceWidth),
height:round((1 / greaterOrEqualSampleSize) * sourceHeight)
}
let scaleFactor = Math.max(1, highestOneBit(Math.min(sourceWidth / outSize.width, sourceHeight / outSize.height)))
if ((scaleFactor < greaterOrEqualSampleSize)) {
scaleFactor = scaleFactor << 1;
}
return scaleFactor
}
}
/*宽高进行等比缩放宽高里面最大的比例先放进去
然后再更据原图的缩放比去适配另一边*/
export class CenterInside implements BaseDownsampling {
getName() {
return "CenterInside"
}
getScaleFactor(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,
downsampType: DownsampleStrategy
): number {
let outSize: Size = {
width: round(Math.min(1, getScale(sourceWidth, sourceHeight, requestedWidth, requestedHeight, downsampType)) * sourceWidth),
height:round(Math.min(1, getScale(sourceWidth, sourceHeight, requestedWidth, requestedHeight, downsampType)) * sourceHeight)
}
//将整型的缩放因子转换为2的次幂采样大小
let scaleFactor = this.getSampleSizeType(sourceWidth, sourceHeight, requestedWidth, requestedHeight,
downsampType) == SampleSizeRounding.QUALITY ?
Math.max(1, highestOneBit(Math.max(sourceWidth / outSize.width, sourceHeight / outSize.height))) :
Math.max(1, highestOneBit(Math.min(sourceWidth / outSize.width, sourceHeight / outSize.height)))
if (this.getSampleSizeType(sourceWidth, sourceHeight, requestedWidth, requestedHeight, downsampType)
== SampleSizeRounding.MEMORY && (scaleFactor < (1 / Math.min(1, getScale(sourceWidth, sourceHeight, requestedWidth, requestedHeight, downsampType))))) {
scaleFactor = scaleFactor << 1;
}
return scaleFactor
}
getSampleSizeType(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,
downsampType: DownsampleStrategy
): SampleSizeRounding {
//如果缩放因子为 1表示没有缩放优先选择质量
if (Math.min(1, getScale(sourceWidth, sourceHeight, requestedWidth, requestedHeight, downsampType)) === 1) {
return SampleSizeRounding.QUALITY
}
//否则,使用 FIL_CENTER 的 SampleSizeRounding 值
return downsampType === DownsampleStrategy.CENTER_OUTSIDE_MEMORY?SampleSizeRounding.MEMORY:SampleSizeRounding.QUALITY
}
}
export enum DownsampleStrategy {
//请求尺寸大于实际尺寸不进行放大
AT_MOST,
//两边自适应内存优先
FIT_CENTER_MEMORY,
//两边自适应质量优先
FIT_CENTER_QUALITY,
//按照宽高比的最大比进行适配内存优先
CENTER_OUTSIDE_MEMORY,
//按照宽高比的最大比进行适配质量优先
CENTER_OUTSIDE_QUALITY,
//宽高进行等比缩放宽高里面最小的比例先放进去,然后再根据原图的缩放比去适配
AT_LEAST,
//不进行降采样
NONE,
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DownsampleStrategy } from './DownsampleStartegy';
export enum SampleSizeRounding {
/**
* Prefer to round the sample size up so that the image is downsampled to smaller than the
* requested size to use less memory.
*/
//(内存优先)
MEMORY,
/**
* Prefer to round the sample size down so that the image is downsampled to larger than the
* requested size to maintain quality at the expense of extra memory usage.
*/
//(质量优先)
QUALITY
}
//找出给定整数 i 中最高位的1即最左边的1所代表的值
export function highestOneBit(i: number): number {
i |= (i >> 1);
i |= (i >> 2);
i |= (i >> 4);
i |= (i >> 8);
i |= (i >> 16);
return i - (i >>> 1);
}
export function getScale(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,
downsampType: DownsampleStrategy
): number {
if (downsampType === DownsampleStrategy.FIT_CENTER_MEMORY) {
const widthPercentage = requestedWidth / sourceWidth
const heightPercentage = requestedHeight / sourceHeight
return Math.min(widthPercentage, heightPercentage)
} else {
const maxIntegerFactor = Math.max(sourceHeight / requestedHeight, sourceWidth / requestedWidth);
return maxIntegerFactor === 0 ? 1 : 1 / highestOneBit(maxIntegerFactor);
}
}
//四舍五入
export function round(value: number): number {
return Math.floor(value + 0.5);
}

View File

@ -0,0 +1,73 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
AtMost,
CenterInside,
AtLeast,
DownsampleStrategy,
FitCenter,
} from './DownsampleStartegy';
export class Downsampler {
calculateScaling(
typeValue: string,
sourceWidth: number, //原始宽高
sourceHeight: number, //原始宽高
requestWidth: number, //请求宽高
requestHeight: number, //请求宽高
downsampType: DownsampleStrategy,
): Size {
if (sourceHeight <= 0 || sourceWidth <= 0) {
throw new Error(`Invalid width and height, sourceHeight:${sourceHeight}+ sourceWidth:${sourceWidth}`)
}
let downsampler = this.getDownsampler(downsampType);
let scaleFactor: number =
downsampler.getScaleFactor(sourceWidth, sourceHeight, requestWidth, requestHeight, downsampType);//缩放比
//基于上一步得出的采样大小,根据不同的图片类型,计算采样后的图片尺寸
if (typeValue === "png") {
return {
width: Math.floor(sourceWidth / scaleFactor),
height: Math.floor(sourceHeight / scaleFactor)
}
} else if (typeValue === "webp") {
return {
width: Math.round(sourceWidth / scaleFactor),
height: Math.round(sourceHeight / scaleFactor)
}
} else {
return {
width: sourceWidth / scaleFactor,
height: sourceHeight / scaleFactor
}
}
}
getDownsampler(downsampType: DownsampleStrategy) {
switch (downsampType) {
case DownsampleStrategy.FIT_CENTER_MEMORY:
case DownsampleStrategy.FIT_CENTER_QUALITY:
return new FitCenter();
case DownsampleStrategy.AT_MOST:
return new AtMost();
case DownsampleStrategy.CENTER_OUTSIDE_MEMORY:
case DownsampleStrategy.CENTER_OUTSIDE_QUALITY:
return new CenterInside();
case DownsampleStrategy.AT_LEAST:
return new AtLeast();
default:
throw new Error('Unsupported downsampling strategy');
}
}
}

View File

@ -17,6 +17,7 @@ import { ImageKnifeOption } from '../model/ImageKnifeOption';
import { IEngineKey } from './IEngineKey'; import { IEngineKey } from './IEngineKey';
import { PixelMapTransformation } from '../transform/PixelMapTransformation'; import { PixelMapTransformation } from '../transform/PixelMapTransformation';
import { ImageKnifeRequestSource } from '../model/ImageKnifeData'; import { ImageKnifeRequestSource } from '../model/ImageKnifeData';
import { DownsampleStrategy } from '../downsampling/DownsampleStartegy';
@Sendable @Sendable
export class DefaultEngineKey implements IEngineKey { export class DefaultEngineKey implements IEngineKey {
@ -31,6 +32,9 @@ export class DefaultEngineKey implements IEngineKey {
if (imageKnifeOption.transformation) { if (imageKnifeOption.transformation) {
key += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";" key += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";"
} }
if ((imageKnifeOption.downsampleOf !== DownsampleStrategy.NONE && imageKnifeOption.downsampleOf !== undefined)) {
key += "downsampleOf" + imageKnifeOption.downsampleOf +"width="+width+"height="+ height
}
} }
return key return key
} }

View File

@ -18,6 +18,7 @@ import { IEngineKey } from '../key/IEngineKey'
import { PixelMapTransformation } from '../transform/PixelMapTransformation' import { PixelMapTransformation } from '../transform/PixelMapTransformation'
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import { Size } from '@kit.ArkUI' import { Size } from '@kit.ArkUI'
import { DownsampleStrategy } from '../downsampling/DownsampleStartegy'
export interface ImageKnifeData { export interface ImageKnifeData {
source: PixelMap | string, source: PixelMap | string,
@ -103,6 +104,9 @@ export interface RequestJobRequest {
fileCacheFolder: string, fileCacheFolder: string,
isAnimator?: boolean, isAnimator?: boolean,
moduleName?:string, moduleName?:string,
resName?: string resName?: string,
targetWidth: number
targetHeight: number
downsampType: DownsampleStrategy
} }

View File

@ -17,43 +17,61 @@ import common from '@ohos.app.ability.common'
import { CacheStrategy, ImageKnifeData,EventImage } from './ImageKnifeData'; import { CacheStrategy, ImageKnifeData,EventImage } from './ImageKnifeData';
import { PixelMapTransformation } from '../transform/PixelMapTransformation'; import { PixelMapTransformation } from '../transform/PixelMapTransformation';
import { drawing } from '@kit.ArkGraphics2D'; import { drawing } from '@kit.ArkGraphics2D';
import { DownsampleStrategy } from '../downsampling/DownsampleStartegy';
export interface HeaderOptions { export interface HeaderOptions {
key: string; key: string;
value: Object; value: Object;
} }
interface AnimatorType {
@Observed state?: AnimationStatus
export class AnimatorOption { iterations?: number
@Track reverse?: boolean
state?: AnimationStatus = AnimationStatus.Running
@Track
iterations?: number = -1
@Track
reverse?: boolean = false
@Track
onStart?:()=>void onStart?:()=>void
@Track
onFinish?:()=>void onFinish?:()=>void
@Track
onPause?:()=>void onPause?:()=>void
@Track
onCancel?:()=>void onCancel?:()=>void
@Track
onRepeat?:()=>void onRepeat?:()=>void
} }
@ObservedV2
@Observed export class AnimatorOption {
export class ImageKnifeOption { @Trace
state?: AnimationStatus = AnimationStatus.Running
@Trace
iterations?: number = -1
@Trace
reverse?: boolean = false
@Trace
onStart?:()=>void
@Trace
onFinish?:()=>void
@Trace
onPause?:()=>void
@Trace
onCancel?:()=>void
@Trace
onRepeat?:()=>void
constructor(option?:AnimatorType) {
this.state = option?.state
this.iterations = option?.iterations
this.reverse = option?.reverse
this.onStart = option?.onStart
this.onFinish = option?.onFinish
this.onPause = option?.onPause
this.onCancel = option?.onCancel
this.onRepeat = option?.onRepeat
}
}
interface ImageOption {
// 主图资源 // 主图资源
loadSrc: string | PixelMap | Resource = ""; loadSrc: string | PixelMap | Resource
// 占位图 // 占位图
placeholderSrc?: string | PixelMap | Resource; placeholderSrc?: string | PixelMap | Resource
// 失败占位图 // 失败占位图
errorholderSrc?: string | PixelMap | Resource; errorholderSrc?: string | PixelMap | Resource
headerOption?: Array<HeaderOptions>; headerOption?: Array<HeaderOptions>;
// 自定义缓存关键字 // 自定义缓存关键字
signature?: string; signature?: string
// 主图填充效果 // 主图填充效果
objectFit?: ImageFit objectFit?: ImageFit
// 占位图填充效果 // 占位图填充效果
@ -65,16 +83,69 @@ export class ImageKnifeOption {
// 缓存策略 // 缓存策略
writeCacheStrategy?: CacheStrategy writeCacheStrategy?: CacheStrategy
// 仅使用缓存加载数据 // 仅使用缓存加载数据
onlyRetrieveFromCache?: boolean = false; onlyRetrieveFromCache?: boolean;
priority?: taskpool.Priority = taskpool.Priority.LOW priority?: taskpool.Priority
context?: common.UIAbilityContext; context?: common.UIAbilityContext;
progressListener?: (progress: number) => void; progressListener?: (progress: number) => void;
transformation?: PixelMapTransformation transformation?: PixelMapTransformation
onLoadListener?: OnLoadCallBack | undefined; onLoadListener?: OnLoadCallBack | undefined;
onComplete?:(event:EventImage | undefined) => void onComplete?:(event:EventImage | undefined) => void
drawingColorFilter?: ColorFilter | drawing.ColorFilter drawingColorFilter?: ColorFilter | drawing.ColorFilter
constructor() { downsampleOf?: DownsampleStrategy
}
@ObservedV2
export class ImageKnifeOption {
// 主图资源
@Trace loadSrc: string | PixelMap | Resource = "";
// 占位图
placeholderSrc?: string | PixelMap | Resource;
// 失败占位图
errorholderSrc?: string | PixelMap | Resource;
headerOption?: Array<HeaderOptions>;
// 自定义缓存关键字
@Trace signature?: string;
// 主图填充效果
@Trace objectFit?: ImageFit
// 占位图填充效果
placeholderObjectFit?: ImageFit
// 错误图填充效果
errorholderObjectFit?: ImageFit
customGetImage?: (context: Context, src: string | PixelMap | Resource) => Promise<ArrayBuffer | undefined>
@Trace border?: BorderOptions
// 缓存策略
writeCacheStrategy?: CacheStrategy
// 仅使用缓存加载数据
onlyRetrieveFromCache?: boolean = false;
priority?: taskpool.Priority = taskpool.Priority.LOW
context?: common.UIAbilityContext;
progressListener?: (progress: number) => void;
@Trace transformation?: PixelMapTransformation
onLoadListener?: OnLoadCallBack | undefined;
onComplete?:(event:EventImage | undefined) => void
drawingColorFilter?: ColorFilter | drawing.ColorFilter
// 下采样
@Trace downsampleOf: DownsampleStrategy = DownsampleStrategy.NONE
constructor(option?:ImageOption) {
this.loadSrc = option?.loadSrc == undefined ? "" : option?.loadSrc
this.placeholderSrc = option?.placeholderSrc
this.errorholderSrc = option?.errorholderSrc
this.headerOption = option?.headerOption
this.signature = option?.signature
this.objectFit = option?.objectFit
this.placeholderObjectFit = option?.placeholderObjectFit
this.errorholderObjectFit = option?.errorholderObjectFit
this.customGetImage = option?.customGetImage
this.border = option?.border
this.writeCacheStrategy = option?.writeCacheStrategy
this.onlyRetrieveFromCache = option?.onlyRetrieveFromCache
this.priority = option?.priority
this.context = option?.context
this.progressListener = option?.progressListener
this.transformation = option?.transformation
this.onLoadListener = option?.onLoadListener
this.onComplete = option?.onComplete
this.drawingColorFilter = option?.drawingColorFilter
this.downsampleOf = option?.downsampleOf==undefined?DownsampleStrategy.NONE:option?.downsampleOf
} }
} }

View File

@ -15,6 +15,7 @@
import { ImageKnifeOption } from './ImageKnifeOption'; import { ImageKnifeOption } from './ImageKnifeOption';
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import { ImageKnifeRequestSource } from './ImageKnifeData'; import { ImageKnifeRequestSource } from './ImageKnifeData';
import { DownsampleStrategy } from '../downsampling/DownsampleStartegy';
export class ImageKnifeRequest { export class ImageKnifeRequest {
@ -27,18 +28,22 @@ export class ImageKnifeRequest {
ImageKnifeRequestCallback: ImageKnifeRequestCallback ImageKnifeRequestCallback: ImageKnifeRequestCallback
componentVersion: number = 0 componentVersion: number = 0
headers: Map<string,Object> = new Map<string,Object>() headers: Map<string,Object> = new Map<string,Object>()
downsampType?: DownsampleStrategy
constructor(option: ImageKnifeOption, constructor(option: ImageKnifeOption,
uIAbilityContext: common.UIAbilityContext, uIAbilityContext: common.UIAbilityContext,
width: number, width: number,
height: number, height: number,
version: number, version: number,
ImageKnifeRequestCallback: ImageKnifeRequestCallback) { ImageKnifeRequestCallback: ImageKnifeRequestCallback,
downsampType?: DownsampleStrategy
) {
this.imageKnifeOption = option this.imageKnifeOption = option
this.context = uIAbilityContext this.context = uIAbilityContext
this.componentWidth = width this.componentWidth = width
this.componentHeight = height this.componentHeight = height
this.componentVersion = version this.componentVersion = version
this.ImageKnifeRequestCallback = ImageKnifeRequestCallback this.ImageKnifeRequestCallback = ImageKnifeRequestCallback
this.downsampType = downsampType
} }
// RequestOption调用header对于的方法 // RequestOption调用header对于的方法
addHeader(key: string, value: Object) { addHeader(key: string, value: Object) {

View File

@ -176,7 +176,6 @@ export class FileUtils {
let length = stat.size; let length = stat.size;
let buf = new ArrayBuffer(length); let buf = new ArrayBuffer(length);
await fs.read(fd, buf); await fs.read(fd, buf);
await fs.close(fd)
return buf return buf
} catch (error) { } catch (error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

View File

@ -1,16 +1,11 @@
{ {
"modelVersion": "5.0.0", "license": "ISC",
"name": "imageknife",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
"@ohos/gpu_transform": "^1.0.2"
},
"devDependencies": { "devDependencies": {
"@ohos/hypium": "1.0.16" "@ohos/hypium": "1.0.6"
}, },
"dynamicDependencies": {} "name": "imageknife",
} "description": "example description",
"repository": {},
"version": "",
"dependencies": {}
}

View File

@ -14,14 +14,14 @@
*/ */
import { ImageKnife , ImageKnifeComponent ,ImageKnifeOption } from "@ohos/imageknife" import { ImageKnife , ImageKnifeComponent ,ImageKnifeOption } from "@ohos/imageknife"
@Component @ComponentV2
export struct IndexComponent { export struct IndexComponent {
@State imageKnifeOption: ImageKnifeOption = { @Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.startIcon') loadSrc: $r('app.media.startIcon')
} })
build() { build() {
Column() { Column() {
Button("预加载").onClick((event: ClickEvent) => { Button($r('app.string.Preload')).onClick((event: ClickEvent) => {
ImageKnife.getInstance() ImageKnife.getInstance()
.preLoadCache('https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp') .preLoadCache('https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp')
.then((data) => { .then((data) => {

View File

@ -3,6 +3,10 @@
{ {
"name": "shared_desc", "name": "shared_desc",
"value": "description" "value": "description"
},
{
"name": "Preload",
"value": "Preload"
} }
] ]
} }

View File

@ -0,0 +1,8 @@
{
"string": [
{
"name": "Preload",
"value": "预加载"
}
]
}