!3 ImageKnife first commit with hvigor build
Merge pull request !3 from 周黎生/master
This commit is contained in:
commit
dfa6a3409e
|
@ -1,17 +1,4 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
/entry/.preview
|
||||
.cxx
|
||||
/node_modules
|
||||
.idea
|
||||
/local.properties
|
||||
/.idea
|
||||
**/build
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<filefilterlist>
|
||||
<filefilter name="copyrightPolicyFilter" desc="Filters for compatibility,license header policies">
|
||||
<filteritem type="filename" name="hvigorfile.js" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/>
|
||||
<filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
|
||||
<filteritem type="filepath" name="imageknife/src/main/ets/components/imageknife/pngj/UPNG.js" desc="使用开源库UPNG,使用其默认版权头,无需修改"/>
|
||||
</filefilter>
|
||||
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
|
||||
<filteritem type="filename" name="hvigorfile.js" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/>
|
||||
<filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
|
||||
<filteritem type="filepath" name="imageknife/src/main/ets/components/imageknife/pngj/UPNG.js" desc="使用开源库UPNG,使用其默认版权头,无需修改"/>
|
||||
</filefilter>
|
||||
<filefilter name="defaultPolicyFilter" desc="Filters for copyright header policies">
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
|
@ -2,21 +2,21 @@
|
|||
{
|
||||
"Name": "glide",
|
||||
"License": "under one or more license",
|
||||
"License File": "https://github.com/bumptech/glide/blob/master/LICENSE",
|
||||
"License File": "https://github.com/bumptech/imageknife/blob/master/LICENSE",
|
||||
"Version Number": "4.13.1",
|
||||
"Owner" : "bumptech"
|
||||
"Upstream URL": "https://github.com/bumptech/glide",
|
||||
"Description": "An image loading and caching library for Android focused on smooth scrolling"
|
||||
"Upstream URL": "https://github.com/bumptech/imageknife",
|
||||
"Description": "An image loading and caching library focused on smooth scrolling"
|
||||
},
|
||||
|
||||
{
|
||||
"Name": "glide-transformations",
|
||||
"License": "Apache License 2.0",
|
||||
"License File": "https://github.com/wasabeef/glide-transformations/blob/main/LICENSE",
|
||||
"License File": "https://github.com/wasabeef/imageknife-transformations/blob/main/LICENSE",
|
||||
"Version Number": "4.3.0",
|
||||
"Owner" : "wasabeef"
|
||||
"Upstream URL": "https://github.com/wasabeef/glide-transformations",
|
||||
"Description": " An Android transformation library providing a variety of image transformations for Glide. "
|
||||
"Upstream URL": "https://github.com/wasabeef/imageknife-transformations",
|
||||
"Description": " An transformation library providing a variety of image transformations for Glide. "
|
||||
},
|
||||
|
||||
{
|
||||
|
@ -26,7 +26,7 @@
|
|||
"Version Number": "2.6.0",
|
||||
"Owner" : "facebook"
|
||||
"Upstream URL": "https://github.com/facebook/fresco",
|
||||
"Description": " An Android library for managing images and the memory they use. "
|
||||
"Description": " An library for managing images and the memory they use. "
|
||||
},
|
||||
|
||||
{
|
||||
|
@ -56,7 +56,7 @@
|
|||
"Version Number": "2.2.8",
|
||||
"Owner" : " Yalantis"
|
||||
"Upstream URL": "https://github.com/Yalantis/uCrop",
|
||||
"Description": " Image Cropping Library for Android "
|
||||
"Description": " Image Cropping Library "
|
||||
}
|
||||
|
||||
]
|
208
README.md
208
README.md
|
@ -4,18 +4,36 @@
|
|||
|
||||
## 简介
|
||||
|
||||
本项目基于开源库 [Glide](https://github.com/bumptech/glide) 进行OpenHarmony的自研版本
|
||||
|
||||
- 支持内存缓存,使用LRUCache算法,对图片数据进行内存缓存
|
||||
- 支持磁盘缓存,对于下载图片会保存一份至磁盘当中。
|
||||
- 支持进行图片变换。
|
||||
- 支持用户配置参数使用:(例如:配置是否开启第一级内存缓存,配置磁盘缓存策略,配置仅使用缓存加载数据,配置图片变换效果,配置占位图,配置加载失败占位图等)。
|
||||
- 推荐使用GlideImage组件配合GlideOption参数来实现功能
|
||||
- 支持用户自定义配置实现能力参考GlideImage组件中对于入参GlideOption的处理
|
||||
- 支持磁盘缓存,对于下载图片会保存一份至磁盘当中
|
||||
- 支持进行图片变换
|
||||
- 支持用户配置参数使用:(例如:配置是否开启第一级内存缓存,配置磁盘缓存策略,配置仅使用缓存加载数据,配置图片变换效果,配置占位图,配置加载失败占位图等)
|
||||
- 推荐使用ImageKnifeComponent组件配合ImageKnifeOption参数来实现功能
|
||||
- 支持用户自定义配置实现能力参考ImageKnifeComponent组件中对于入参ImageKnifeOption的处理
|
||||
|
||||
## 下载安装
|
||||
|
||||
1.参考安装教程 [如何安装OpenHarmony npm包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_npm_usage.md)
|
||||
|
||||
2.安装命令如下:
|
||||
|
||||
```
|
||||
npm install @ohos/imageknife --save
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 使用说明
|
||||
|
||||
[跳转至代码示例](##'代码示例')
|
||||
|
||||
## 目录
|
||||
|
||||
```
|
||||
/entry/src/
|
||||
- main/ets/MainAbility
|
||||
/imageknife/src/
|
||||
- main/ets/components
|
||||
- cache # 缓存相关内容
|
||||
- diskstrategy # 缓存策略
|
||||
- key # 缓存key生成策略
|
||||
|
@ -28,7 +46,7 @@
|
|||
- LruCache.ets # 内存LRU缓存策略
|
||||
- Md5.ets # MD5算法
|
||||
|
||||
- glide # glide主要内容
|
||||
- imageknife # imageknife主要内容
|
||||
- compress # 压缩相关
|
||||
- constants # 常量相关
|
||||
- entry # 部分数据结构
|
||||
|
@ -36,26 +54,28 @@
|
|||
- interface # 接口相关
|
||||
- networkmanage # 网络相关
|
||||
- pngj # pngj相关
|
||||
- requestmanage # Glide请求相关
|
||||
- requestmanage # imageknife请求相关
|
||||
- resourcemanage # 本地资源解析相关
|
||||
- transform # 图片变换相关
|
||||
- utils # 工具类相关
|
||||
- Glide.ets # Glide门面,app持久化类
|
||||
- GlideData.ets # 数据封装
|
||||
- GlideImage.ets # 自定义控件封装
|
||||
- GlideOption.ets # 用户传参数封装
|
||||
- ImageKnife.ets # imageknife门面,app持久化类
|
||||
- ImageKnifeData.ets # 数据封装
|
||||
- ImageKnifeComponent.ets # 自定义控件封装
|
||||
- ImageKnifeOption.ets # 用户传参数封装
|
||||
- PixelMapPack.ets # PixelMap封装
|
||||
- RequestOption.ets # 用户设置参数封装
|
||||
|
||||
/entry/src/
|
||||
- main/ets/MainAbility
|
||||
- pages # 测试page页面列表
|
||||
- basicTestFeatureAbilityPage.ets # 测试元能力
|
||||
- basicTestFileIOPage.ets # 测试fileio
|
||||
- basicTestMediaImage.ets # 测试媒体image
|
||||
- basicTestResourceManagerPage.ets # 测试本地资源解析
|
||||
- CompressPage.ets # 压缩页面
|
||||
- compressPage.ets # 压缩页面
|
||||
- frescoImageTestCasePage.ets # 测试属性动画组件切换
|
||||
- frescoLayerTestCasePage.ets # 测试GlideImage组件切换配合属性动画
|
||||
- frescoRetryTestCasePage.ets # 测试GlideImage加载失败重试
|
||||
- frescoLayerTestCasePage.ets # 测试ImageKnifeComponent组件切换配合属性动画
|
||||
- frescoRetryTestCasePage.ets # 测试ImageKnifeComponent加载失败重试
|
||||
- index.ets # 测试页面入口
|
||||
- indexFresco.ets # 二级测试页面入口
|
||||
- loadNetworkTestCasePage.ets # 网络加载测试
|
||||
|
@ -64,17 +84,17 @@
|
|||
- storageTestDiskLruCache.ets # 磁盘缓存测试
|
||||
- storageTestLruCache.ets # 内存缓存测试
|
||||
- testAllCacheInfoPage.ets # 所有缓存信息获取测试
|
||||
- testAllTypeGlideImagePage.ets # 所有类型图片加载测试
|
||||
- testAllTypeImageKnifeComponentPage.ets # 所有类型图片加载测试
|
||||
- testAllTypeNativeImagePage.ets # 所有类型本地图片加载测试
|
||||
- testGifDontAnimatePage.ets # gif加载静态图片测试
|
||||
- testGlideOptionChangedPage.ets # GlideOption数据切换测试
|
||||
- testGlideOptionChangedPage2.ets # GlideOption数据切换测试
|
||||
- testImageKnifeOptionChangedPage.ets # ImageKnifeOption数据切换测试
|
||||
- testImageKnifeOptionChangedPage2.ets # ImageKnifeOption数据切换测试
|
||||
- testMultiThreadWorkerPage2.ets # 多线程测试
|
||||
- testPlaceholderPage.ets # 加载占位图测试
|
||||
- testPreloadPage.ets # 预加载测试
|
||||
- testResourceManagerPage.ets # 解析本地资源测试
|
||||
- TransformPixelMapPage.ets # 所有类型变换测试
|
||||
- transformTestCasePage.ets # 所有类型变换配合GlideImage测试
|
||||
- transformPixelMapPage.ets # 所有类型变换测试
|
||||
- transformTestCasePage.ets # 所有类型变换配合ImageKnifeComponent测试
|
||||
|
||||
- workers # 测试worker多线程
|
||||
- worker1.js # worker多线程测试
|
||||
|
@ -84,27 +104,24 @@
|
|||
|
||||
### RequestOpton 用户配置参数
|
||||
|
||||
| 方法名 | 入参 | 接口描述 |
|
||||
| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
|
||||
| load(src: string \| PixelMap \| Resource) | string \| PixelMap \| Resource | 待加载图片的资源 |
|
||||
| setImageViewSize(imageSize: { width: number, height: number }) | { width: number, height: number } | 传入显示图片组件的大小,变换的时候需要作为参考 |
|
||||
| diskCacheStrategy(strategy: DiskStrategy) | DiskStrategy | 配置磁盘缓存策略 NONE SOURCE RESULT ALL AUTOMATIC |
|
||||
| placeholder(src: PixelMap \| Resource, func?: AsyncSuccess<PixelMap>) | src: PixelMap \| Resource, func?: AsyncSuccess<PixelMap> | 配置占位图,其中func为数据回调函数 |
|
||||
| errorholder(src: PixelMap \| Resource, func?: AsyncSuccess<PixelMap>) | src: PixelMap \| Resource, func?: AsyncSuccess<PixelMap> | 配置加载失败占位图,其中func为数据回调函数 |
|
||||
| addListener(func: AsyncCallback<PixelMap>) | func: AsyncCallback<PixelMap> | 配置整个监听回调,数据正常加载返回,加载失败返回错误信息 |
|
||||
| thumbnail(sizeMultiplier:number, func?: AsyncSuccess<GlideData>) | sizeMultiplier:number, func?: AsyncSuccess<GlideData> | 设置缩略图比例,缩略图返回后,加载并展示缩略图 |
|
||||
| addProgressListener(func?: AsyncSuccess<string>){ this.progressFunc = func; return this; } | func?: AsyncSuccess<string> | 设置网络下载百分比监听,返回数据加载百分比数值 |
|
||||
| addRetryListener(func?: AsyncSuccess<any>){ this.retryFunc = func; return this; } | func?: AsyncSuccess<any> | 设置重试监听 |
|
||||
| addAllCacheInfoCallback(func: IAllCacheInfoCallback) | func: IAllCacheInfoCallback | 设置获取所有缓存信息监听 |
|
||||
| skipMemoryCache(skip: boolean) | skip: boolean | 配置是否跳过内存缓存 |
|
||||
| retrieveDataFromCache(flag: boolean) | flag: boolean | 配置仅从缓存中加载数据 |
|
||||
| transform(transform: BaseTransform<PixelMap>) | transform: BaseTransform<PixelMap> | 配置自定义变换类型 |
|
||||
| centerCrop(fd: number, out_width: number, out_height: number, callback?: AsyncTransform<Promise<PixelMap>>) | fd: number, out_width: number, out_height: number, callback?: AsyncTransform<Promise<PixelMap>> | 静态方法可以根据图片文件,目标显示大小,进行对应centerCrop |
|
||||
| rotateImage(fd: number, degreesToRotate: number) | fd: number, degreesToRotate: number | 静态方法可以根据图片文件,和旋转角度,进行对应rotateImaroge |
|
||||
| centerInside(fd: number, out_width: number, out_height: number, callback?: AsyncTransform<Promise<PixelMap>>) | fd: number, out_width: number, out_height: number, callback?: AsyncTransform<Promise<PixelMap>> | 静态方法可以根据图片文件,目标显示大小,进行对应centerInside |
|
||||
| fitCenter(fd: number, out_width: number, out_height: number , callback?: AsyncTransform<Promise<PixelMap>>) | fd: number, out_width: number, out_height: number , callback?: AsyncTransform<Promise<PixelMap>> | 静态方法可以根据图片文件,目标显示大小,进行对应fitCenter |
|
||||
| 方法名 | 入参 | 接口描述 |
|
||||
| ------------------------------------------------------------ | ---------------------------------------------------------- | -------------------------------------------------------- |
|
||||
| load(src: string \| PixelMap \| Resource) | string \| PixelMap \| Resource | 待加载图片的资源 |
|
||||
| setImageViewSize(imageSize: { width: number, height: number }) | { width: number, height: number } | 传入显示图片组件的大小,变换的时候需要作为参考 |
|
||||
| diskCacheStrategy(strategy: DiskStrategy) | DiskStrategy | 配置磁盘缓存策略 NONE SOURCE RESULT ALL AUTOMATIC |
|
||||
| placeholder(src: PixelMap \| Resource, func?: AsyncSuccess<PixelMap>) | src: PixelMap \| Resource, func?: AsyncSuccess<PixelMap> | 配置占位图,其中func为数据回调函数 |
|
||||
| errorholder(src: PixelMap \| Resource, func?: AsyncSuccess<PixelMap>) | src: PixelMap \| Resource, func?: AsyncSuccess<PixelMap> | 配置加载失败占位图,其中func为数据回调函数 |
|
||||
| addListener(func: AsyncCallback<PixelMap>) | func: AsyncCallback<PixelMap> | 配置整个监听回调,数据正常加载返回,加载失败返回错误信息 |
|
||||
| thumbnail(sizeMultiplier:number, func?: AsyncSuccess<ImageKnifeData>) | sizeMultiplier:number, func?: AsyncSuccess<ImageKnifeData> | 设置缩略图比例,缩略图返回后,加载并展示缩略图 |
|
||||
| addProgressListener(func?: AsyncSuccess<string>){ this.progressFunc = func; return this; } | func?: AsyncSuccess<string> | 设置网络下载百分比监听,返回数据加载百分比数值 |
|
||||
| addRetryListener(func?: AsyncSuccess<any>){ this.retryFunc = func; return this; } | func?: AsyncSuccess<any> | 设置重试监听 |
|
||||
| addAllCacheInfoCallback(func: IAllCacheInfoCallback) | func: IAllCacheInfoCallback | 设置获取所有缓存信息监听 |
|
||||
| skipMemoryCache(skip: boolean) | skip: boolean | 配置是否跳过内存缓存 |
|
||||
| retrieveDataFromCache(flag: boolean) | flag: boolean | 配置仅从缓存中加载数据 |
|
||||
|
||||
### Glide 启动器/门面类
|
||||
同时支持[图片变换相关](##'图片变换相关')接口
|
||||
|
||||
### ImageKnife 启动器/门面类
|
||||
|
||||
| 方法名 | 入参 | 接口描述 |
|
||||
| ------------------------------- | ---------------------- | ---------------------------------- |
|
||||
|
@ -123,42 +140,47 @@
|
|||
|
||||
### 图片变换相关
|
||||
|
||||
| 使用方法 | 类型 | 相关描述 |
|
||||
| ------------------------------------------------------------ | ---------------------------------- | -------------- |
|
||||
| request.transforms(new BlurTransformation()) | BlurTransformation | 模糊处理 |
|
||||
| request.transforms(new BrightnessFilterTransformation()) | BrightnessFilterTransformation | 亮度滤波器 |
|
||||
| request.transforms(new ContrastFilterTransformation()) | ContrastFilterTransformation | 对比度滤波器 |
|
||||
| request.transforms(new CropCircleTransformation()) | CropCircleTransformation | 圆形剪裁显示 |
|
||||
| request.transforms(new CropCircleWithBorderTransformation()) | CropCircleWithBorderTransformation | 圆环展示 |
|
||||
| request.transforms(new CropSquareTransformation()) | CropSquareTransformation | 正方形剪裁 |
|
||||
| request.transforms(new CropTransformation()) | CropTransformation | 自定义矩形剪裁 |
|
||||
| request.transforms(new GrayscaleTransformation()) | GrayscaleTransformation | 灰度级转换 |
|
||||
| request.transforms(new InvertFilterTransformation()) | InvertFilterTransformation | 反转滤波器 |
|
||||
| request.transforms(new PixelationFilterTransformation()) | PixelationFilterTransformation | 像素化滤波器 |
|
||||
| request.transforms(new RotateImageTransformation()) | RotateImageTransformation | 图片旋转 |
|
||||
| request.transforms(new RoundedCornersTransformation()) | RoundedCornersTransformation | 圆角剪裁 |
|
||||
| request.transforms(new SepiaFilterTransformation()) | SepiaFilterTransformation | 乌墨色滤波器 |
|
||||
| request.transforms(new SketchFilterTransformation()) | SketchFilterTransformation | 素描滤波器 |
|
||||
| 使用方法 | 类型 | 相关描述 |
|
||||
| ------------------------------ | ---------------------------------- | ---------------------------------------------------- |
|
||||
| request.centerCrop() | CenterCrop | 可以根据图片文件,目标显示大小,进行对应centerCrop |
|
||||
| request.centerInside() | CenterInside | 可以根据图片文件,目标显示大小,进行对应centerInside |
|
||||
| request.fitCenter() | FitCenter | 可以根据图片文件,目标显示大小,进行对应fitCenter |
|
||||
| request.blur() | BlurTransformation | 模糊处理 |
|
||||
| request.brightnessFilter() | BrightnessFilterTransformation | 亮度滤波器 |
|
||||
| request.contrastFilter() | ContrastFilterTransformation | 对比度滤波器 |
|
||||
| request.cropCircle() | CropCircleTransformation | 圆形剪裁显示 |
|
||||
| request.cropCircleWithBorder() | CropCircleWithBorderTransformation | 圆环展示 |
|
||||
| request.cropSquare() | CropSquareTransformation | 正方形剪裁 |
|
||||
| request.crop() | CropTransformation | 自定义矩形剪裁 |
|
||||
| request.grayscale() | GrayscaleTransformation | 灰度级转换 |
|
||||
| request.invertFilter() | InvertFilterTransformation | 反转滤波器 |
|
||||
| request.pixelationFilter() | PixelationFilterTransformation | 像素化滤波器 |
|
||||
| request.rotateImage() | RotateImageTransformation | 图片旋转 |
|
||||
| request.roundedCorners() | RoundedCornersTransformation | 圆角剪裁 |
|
||||
| request.sepiaFilter() | SepiaFilterTransformation | 乌墨色滤波器 |
|
||||
| request.sketchFilter() | SketchFilterTransformation | 素描滤波器 |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 代码示例
|
||||
|
||||
1.首先初始化全局Glide实例,在app.ets中调用Glide.with()进行初始化
|
||||
1.首先初始化全局ImageKnife实例,在app.ets中调用ImageKnife.with()进行初始化
|
||||
|
||||
```
|
||||
import {Glide} from './glide/Glide.ets'
|
||||
import {ImageKnife} from '@ohos/imageknife'
|
||||
export default {
|
||||
data: {
|
||||
glide: {} // Glide全局占位符
|
||||
imageKnife: {} // ImageKnife全局占位符
|
||||
},
|
||||
onCreate() {
|
||||
this.data.glide = Glide.with();// Glide占位符全局初始化赋值
|
||||
this.data.imageKnife = ImageKnife.with();// ImageKnife占位符全局初始化赋值
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2.在页面index.ets中使用Glide
|
||||
2.在页面index.ets中使用ImageKnife
|
||||
|
||||
```
|
||||
@Entry
|
||||
|
@ -168,7 +190,7 @@ struct Index {
|
|||
|
||||
}
|
||||
|
||||
// 页面初始化完成,生命周期回调函数中 进行调用Glide
|
||||
// 页面初始化完成,生命周期回调函数中 进行调用ImageKnife
|
||||
aboutToAppear() {
|
||||
let requestOption = new RequestOption();
|
||||
requestOptin.load($r('app.media.IceCream'))
|
||||
|
@ -176,14 +198,14 @@ struct Index {
|
|||
//加载成功/失败回调监听
|
||||
})
|
||||
...
|
||||
Glide.call(requestOption)
|
||||
ImageKnife.call(requestOption)
|
||||
}
|
||||
}
|
||||
|
||||
var Glide;
|
||||
var ImageKnife;
|
||||
var defaultTemp = globalThis.exports.default
|
||||
if (defaultTemp != undefined) {
|
||||
Glide = defaultTemp.data.glide;
|
||||
ImageKnife = defaultTemp.data.imageKnife;
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -191,15 +213,15 @@ if (defaultTemp != undefined) {
|
|||
|
||||
#### 推荐使用:
|
||||
|
||||
使用GlideOption作为入参,配合自定义组件GlideImage使用。
|
||||
使用ImageKnifeOption作为入参,配合自定义组件ImageKnifeComponent使用。
|
||||
|
||||
```typescript
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State glideOption1: GlideOption =
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83ericA1Mv66TwicuYOtbDMBcUhv1aa9RJBeAn9uURfcZD0AUGrJebAn1g2AjN0vb2E1XTET7fTuLBNmA/132",
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
|
@ -209,7 +231,7 @@ struct Index {
|
|||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
GlideImage({ glideOption: $glideOption1 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
|
@ -225,15 +247,16 @@ struct Index {
|
|||
##### 步骤1:
|
||||
|
||||
定义自定义类
|
||||
|
||||
```
|
||||
export default class PixelMapPack{
|
||||
|
||||
pixelMap:PixelMap;
|
||||
|
||||
}
|
||||
使用@State关联PixelMapPack
|
||||
```
|
||||
|
||||
使用@State关联PixelMapPack
|
||||
```typescript
|
||||
@State glidePixelMapPack:PixelMapPack = new PixelMapPack();
|
||||
@State imageKnifePixelMapPack:PixelMapPack = new PixelMapPack();
|
||||
width:number = 200;
|
||||
height:number = 200;
|
||||
```
|
||||
|
@ -243,7 +266,7 @@ height:number = 200;
|
|||
在你的component组件中,写下一个Image组件,将基础参数(入参PixelMap,组件的宽、高)配置好
|
||||
|
||||
```
|
||||
Image(this.glidePixelMapPack.pixelMap)
|
||||
Image(this.imageKnifePixelMapPack.pixelMap)
|
||||
.backgroundColor(Color.Grey)
|
||||
.objectFit(ImageFit.Contain)
|
||||
.width(this.width)
|
||||
|
@ -258,40 +281,59 @@ Image(this.glidePixelMapPack.pixelMap)
|
|||
//配置参数
|
||||
let requestOptin = new RequestOption();
|
||||
//加载本地图片
|
||||
requestOptin.load($r('app.media.IceCream'))
|
||||
requestOptin.load($r('app.media.jpgSample'))
|
||||
.addListener((err,data) => {
|
||||
//加载成功/失败回调监听
|
||||
})
|
||||
.placeholder( $r('app.media.icon_loading'), (data)=>{
|
||||
// 占位图回调监听
|
||||
})
|
||||
.errorholder(this.glideOption.errorholderSrc, (data)=>{
|
||||
.errorholder( $r('app.media.icon_failed'), (data)=>{
|
||||
// 失败占位图回调监听
|
||||
})
|
||||
.thumbnail(this.glideOption.thumbSizeMultiplier, (data) => {
|
||||
.thumbnail(0.3, (data) => {
|
||||
// 缩略图加载成功回调
|
||||
})
|
||||
// 一定要把控件大小传给RequestOption,图片变换必须
|
||||
.setImageViewSize({width:this.width, height:this.height})
|
||||
.setImageViewSize({width:200, height:200})
|
||||
// 设置缓存策略
|
||||
.diskCacheStrategy(new Strategy())
|
||||
.diskCacheStrategy(new AUTOMATIC())
|
||||
.addProgressListener((percentValue: string) => {
|
||||
// 图片网络加载进度条百分比回调
|
||||
})
|
||||
.addRetryListener((error: any) => {
|
||||
// 加载失败重试监听 图片加载失败时优先展示重试图层,点击重试图层,会重新进行一次加载流程
|
||||
})
|
||||
.transforms(new RoundedCornersTransformation({top:10}))
|
||||
// 左上圆角10pixel像素点
|
||||
.roundedCorners({top:10})
|
||||
// 启动加载流程,执行结果将会返回到上面的回调接口中
|
||||
Glide.call(requestOptin);
|
||||
ImageKnife.call(requestOptin);
|
||||
```
|
||||
|
||||
##### 步骤4:
|
||||
|
||||
更多细节设置请参考自定义Component的GlideImage实现
|
||||
更多细节设置请参考自定义Component的ImageKnifeComponent实现
|
||||
|
||||
## 演示
|
||||
|
||||
<img src="screenshot/g3.gif" width="50%"/>
|
||||
|
||||
<img src="screenshot/g1.gif" width="50%"/><img src="screenshot/g2.gif" width="50%"/>
|
||||
|
||||
## 兼容性
|
||||
|
||||
支持OpenHarmony API version 8 及以上版本
|
||||
|
||||
## 开源协议
|
||||
|
||||
[协议详见](https://gitee.com/openharmony-tpc/ImageKnife/blob/master/LICENSE)
|
||||
|
||||
## 贡献代码
|
||||
|
||||
使用过程中发现任何问题都可以提[issue](https://gitee.com/openharmony-tpc/ImageKnife/issues)给我们,当然,我们也非常欢迎你给我们发[PR](https://gitee.com/openharmony-tpc/ImageKnife/issues)
|
||||
|
||||
## 遗留问题
|
||||
|
||||
1.图片变换缓慢(待优化)
|
||||
|
||||
2.目前只支持一种图片变换效果
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"app": {
|
||||
"signingConfigs": [
|
||||
{
|
||||
"name": "default",
|
||||
"material": {
|
||||
"certpath": "C:\\Users\\zwx1045834\\.ohos\\config\\openharmony\\auto_ohos.cer",
|
||||
"storePassword": "000000184CD86AF7B78D3E3B6C36B9221705137AC28BD8A341A757477E5DC27D95E6A0DFD5EB51AE",
|
||||
"keyAlias": "debugKey",
|
||||
"keyPassword": "00000018DAB1AB9C9DF6E7C4D35BE8EAF4323EFA49131AB39C65BA5C44DE6D3879C6B31AA70D1E14",
|
||||
"profile": "C:\\Users\\zwx1045834\\.ohos\\config\\openharmony\\auto_ohos_default_com.example.imageknifegiteepro.p7b",
|
||||
"signAlg": "SHA256withECDSA",
|
||||
"storeFile": "C:\\Users\\zwx1045834\\.ohos\\config\\openharmony\\auto_ohos.p12"
|
||||
}
|
||||
}
|
||||
],
|
||||
"compileSdkVersion": 8,
|
||||
"compatibleSdkVersion": 8,
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default",
|
||||
}
|
||||
]
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
"name": "entry",
|
||||
"srcPath": "./entry",
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"applyToProducts": [
|
||||
"default"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "imageknife",
|
||||
"srcPath": "./imageknife"
|
||||
}
|
||||
]
|
||||
}
|
35
build.gradle
35
build.gradle
|
@ -1,35 +0,0 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
apply plugin: 'com.huawei.ohos.app'
|
||||
|
||||
//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510
|
||||
ohos {
|
||||
compileSdkVersion 8
|
||||
supportSystem "standard"
|
||||
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://repo.huaweicloud.com/repository/maven/'
|
||||
}
|
||||
maven {
|
||||
url 'https://developer.huawei.com/repo/'
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.huawei.ohos:hap:3.0.5.2'
|
||||
classpath 'com.huawei.ohos:decctest:1.2.7.2'
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://repo.huaweicloud.com/repository/maven/'
|
||||
}
|
||||
maven {
|
||||
url 'https://developer.huawei.com/repo/'
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
/build
|
||||
/node_modules
|
||||
/.preview
|
||||
/build
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"apiType": 'faMode',
|
||||
"buildOption": {
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
},
|
||||
{
|
||||
"name": "ohosTest",
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
apply plugin: 'com.huawei.ohos.hap'
|
||||
//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510
|
||||
ohos {
|
||||
compileSdkVersion 8
|
||||
defaultConfig {
|
||||
compatibleSdkVersion 8
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
proguardOpt {
|
||||
proguardEnabled false
|
||||
rulesFiles 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
||||
module.exports = require('@ohos/hvigor-ohos-plugin').legacyHapTasks
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "entry",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@ohos/imageknife": {
|
||||
"version": "file:../imageknife",
|
||||
"requires": {
|
||||
"pako": "^1.0.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"pako": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "http://mirrors.tools.huawei.com/npm/pako/-/pako-1.0.11.tgz",
|
||||
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"license": "Apache License 2.0",
|
||||
"devDependencies": {},
|
||||
"name": "entry",
|
||||
"ohos": {
|
||||
"org": "huawei",
|
||||
"directoryLevel": "module",
|
||||
"buildTool": "hvigor"
|
||||
},
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@ohos/imageknife": "file:../imageknife"
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
# config module specific ProGuard rules here.
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"app": {
|
||||
"bundleName": "com.huawei.mydemoall",
|
||||
"vendor": "huawei",
|
||||
"vendor": "example",
|
||||
"bundleName": "com.example.imageknifegiteepro",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
|
@ -15,21 +15,11 @@
|
|||
}
|
||||
},
|
||||
"module": {
|
||||
"package": "com.bumptech.glidejs_ohos",
|
||||
"name": ".MyApplication",
|
||||
"mainAbility": ".MainAbility",
|
||||
"srcPath": "",
|
||||
"deviceType": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"default"
|
||||
"tablet"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry",
|
||||
"moduleType": "entry",
|
||||
"installationFree": false
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"skills": [
|
||||
|
@ -48,13 +38,22 @@
|
|||
"name": ".MainAbility",
|
||||
"srcLanguage": "ets",
|
||||
"icon": "$media:icon",
|
||||
"description": "$string:mainability_description",
|
||||
"description": "$string:ImageKnife_OHOS",
|
||||
"formsEnabled": false,
|
||||
"label": "$string:GlideJS_OHOS",
|
||||
"label": "$string:ImageKnife_OHOS",
|
||||
"type": "page",
|
||||
"launchType": "standard"
|
||||
}
|
||||
],
|
||||
"distro": {
|
||||
"moduleType": "entry",
|
||||
"installationFree": false,
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry"
|
||||
},
|
||||
"package": "com.example.entry",
|
||||
"srcPath": "",
|
||||
"name": ".entry",
|
||||
"reqPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.READ_USER_STORAGE"
|
||||
|
@ -64,7 +63,7 @@
|
|||
"reason": "Api call",
|
||||
"usedScene": {
|
||||
"ability": [
|
||||
"com.zls.glidejscache.MainAbility"
|
||||
"com.example.imageknifegiteepro.MainAbility"
|
||||
],
|
||||
"when": "always"
|
||||
}
|
||||
|
@ -78,7 +77,7 @@
|
|||
"usedScene": {
|
||||
"when": "always",
|
||||
"ability": [
|
||||
"com.zls.glidejscache.MainAbility"
|
||||
"com.example.imageknifegiteepro.MainAbility"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -88,7 +87,7 @@
|
|||
"usedScene": {
|
||||
"when": "always",
|
||||
"ability": [
|
||||
"com.zls.glidejscache.MainAbility"
|
||||
"com.example.imageknifegiteepro.MainAbility"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -111,27 +110,24 @@
|
|||
"pages/basicTestResourceManagerPage",
|
||||
"pages/storageTestLruCache",
|
||||
"pages/storageTestDiskLruCache",
|
||||
"pages/testMemoryCachePage",
|
||||
"pages/transformTestCasePage",
|
||||
"pages/pngjTestCasePage",
|
||||
"pages/testAllTypeGlideImagePage",
|
||||
"pages/testAllTypeImageKnifeComponentPage",
|
||||
"pages/testAllTypeNativeImagePage",
|
||||
"pages/loadResourceTestCasePage",
|
||||
"pages/loadNetworkTestCasePage",
|
||||
"pages/showErrorholderTestCasePage",
|
||||
"pages/TransformPixelMapPage",
|
||||
"pages/transformPixelMapPage",
|
||||
"pages/testGifDontAnimatePage",
|
||||
"pages/testPreloadPage",
|
||||
"pages/testGlideOptionChangedPage",
|
||||
"pages/testGlideOptionChangedPage2",
|
||||
"pages/CompressPage",
|
||||
"pages/testImageKnifeOptionChangedPage",
|
||||
"pages/testImageKnifeOptionChangedPage2",
|
||||
"pages/compressPage",
|
||||
"pages/testAllCacheInfoPage",
|
||||
"pages/testResourceManagerPage",
|
||||
"pages/testMultiThreadWorkerPage2",
|
||||
"pages/testGlideOptionChangedPage",
|
||||
"pages/CropImagePage",
|
||||
"pages/networkTestCasePage",
|
||||
"pages/jpegProgressTestCasePage"
|
||||
"pages/testImageKnifeOptionChangedPage",
|
||||
"pages/cropImagePage"
|
||||
],
|
||||
"name": ".MainAbility",
|
||||
"window": {
|
||||
|
|
|
@ -14,17 +14,14 @@
|
|||
*/
|
||||
import app from '@system.app';
|
||||
|
||||
import {Glide} from './glide/Glide.ets'
|
||||
import {ImageKnife} from '@ohos/imageknife'
|
||||
|
||||
export default {
|
||||
data: {
|
||||
glide: {} // Glide
|
||||
imageKnife: {} // ImageKnife
|
||||
},
|
||||
onCreate() {
|
||||
this.data.glide = Glide.with();
|
||||
app.setImageCacheCount(100);
|
||||
app.setImageRawDataCacheSize(104857600)
|
||||
app.setImageFileCacheSize(209715200)
|
||||
this.data.imageKnife = ImageKnife.with();
|
||||
},
|
||||
onDestroy() {
|
||||
|
||||
|
|
|
@ -1,303 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import {GlideOption} from '../glide/GlideOption.ets'
|
||||
import {RequestOption} from '../glide/RequestOption.ets'
|
||||
import {GlideData} from '../glide/GlideData.ets'
|
||||
import {PixelMapPack} from '../glide/PixelMapPack.ets'
|
||||
import {Base64} from '../cache/Base64.ets'
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import image from '@ohos.multimedia.image';
|
||||
|
||||
@Component
|
||||
export struct GlideImage {
|
||||
@Watch('watchGlideOption') @Link glideOption: GlideOption;
|
||||
@State glidePixelMapPack: PixelMapPack = new PixelMapPack();
|
||||
@State glideResource: Resource = $r('app.media.icon_loading')
|
||||
@State glideString: string = ''
|
||||
@State normalPixelMap: boolean = true;
|
||||
@State normalResource: boolean = true;
|
||||
previousData: GlideData = null;
|
||||
nowData: GlideData = null;
|
||||
@State percentVisible: Visibility = Visibility.Visible
|
||||
@State retryVisible: Visibility = Visibility.Visible
|
||||
@State imageVisible: Visibility = Visibility.Visible
|
||||
@State percent: string = '0%'
|
||||
@State percentWidth: string = '0%';
|
||||
@State percentHeight: string = '0%';
|
||||
@State retryWidth: string = '0%';
|
||||
@State retryHeight: string = '0%';
|
||||
@State imageWidth: string = '100%';
|
||||
@State imageHeight: string = '100%';
|
||||
|
||||
hasRetry:boolean = false;
|
||||
|
||||
build() {
|
||||
Stack() {
|
||||
|
||||
Text(this.percent)
|
||||
.fontSize(this.glideOption.size ? Math.min(this.glideOption.size.height, this.glideOption.size.width) / 2 : 24)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.visibility(this.retryVisible)
|
||||
.width(this.percentWidth)
|
||||
.height(this.percentHeight)
|
||||
|
||||
Image($r('app.media.icon_retry'))
|
||||
.onClick(()=>{
|
||||
this.retryClick();
|
||||
})
|
||||
.visibility(this.retryVisible)
|
||||
.width(this.retryWidth)
|
||||
.height(this.retryHeight)
|
||||
|
||||
|
||||
|
||||
Image(this.normalPixelMap ? this.glidePixelMapPack.pixelMap : (this.normalResource ? this.glideResource : this.glideString))
|
||||
.objectFit(this.glideOption.imageFit ? this.glideOption.imageFit : ImageFit.Fill)
|
||||
.visibility(this.imageVisible)
|
||||
.width(this.imageWidth)
|
||||
.height(this.imageHeight)
|
||||
}
|
||||
.width(this.glideOption.size ? this.glideOption.size.width : '100%')
|
||||
.height(this.glideOption.size ? this.glideOption.size.height : '100%')
|
||||
.backgroundColor(this.glideOption.backgroundColor ? this.glideOption.backgroundColor : Color.White)
|
||||
.margin(this.glideOption.margin ? this.glideOption.margin : { left: 0, top: 0, right: 0, bottom: 0 })
|
||||
}
|
||||
|
||||
watchGlideOption() {
|
||||
this.glideExecute();
|
||||
}
|
||||
|
||||
retryClick(){
|
||||
this.hasRetry = true;
|
||||
this.glideExecute();
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
console.log('glideImage aboutToAppear happened!')
|
||||
this.glideExecute();
|
||||
}
|
||||
|
||||
configNecessary(request: RequestOption){
|
||||
// 为了测试重试加载 串讲完成后删除
|
||||
if(this.glideOption.loadSrc == 'https://hbimg.huabanimg.com/testRetryxxxx' && this.hasRetry){
|
||||
request.load('https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp')
|
||||
.addListener((err, data) => {
|
||||
this.glideChangeSource(data)
|
||||
this.animateTo('image');
|
||||
return false;
|
||||
})
|
||||
}else {
|
||||
|
||||
request.load(this.glideOption.loadSrc)
|
||||
.addListener((err, data) => {
|
||||
this.glideChangeSource(data)
|
||||
this.animateTo('image');
|
||||
return false;
|
||||
})
|
||||
}
|
||||
|
||||
if (this.glideOption.size) {
|
||||
request.setImageViewSize(this.glideOption.size)
|
||||
}
|
||||
}
|
||||
|
||||
configCacheStrategy(request: RequestOption){
|
||||
if (this.glideOption.onlyRetrieveFromCache) {
|
||||
request.retrieveDataFromCache(this.glideOption.onlyRetrieveFromCache)
|
||||
}
|
||||
|
||||
if (this.glideOption.isCacheable) {
|
||||
request.skipMemoryCache(!this.glideOption.isCacheable)
|
||||
}
|
||||
|
||||
if (this.glideOption.strategy) {
|
||||
request.diskCacheStrategy(this.glideOption.strategy)
|
||||
}
|
||||
if (this.glideOption.allCacheInfoCallback) {
|
||||
request.addAllCacheInfoCallback(this.glideOption.allCacheInfoCallback)
|
||||
}
|
||||
}
|
||||
|
||||
configDisplay(request: RequestOption){
|
||||
if(this.glideOption.animateDuration >= 0){
|
||||
request.animateDuraction = this.glideOption.animateDuration;
|
||||
}
|
||||
if (this.glideOption.placeholderSrc) {
|
||||
request.placeholder(this.glideOption.placeholderSrc, (data) => {
|
||||
this.glideChangeSource(data)
|
||||
this.animateTo('image');
|
||||
})
|
||||
}
|
||||
if (this.glideOption.thumbSizeMultiplier) {
|
||||
request.thumbnail(this.glideOption.thumbSizeMultiplier, (data) => {
|
||||
this.glideChangeSource(data)
|
||||
this.animateTo('image');
|
||||
})
|
||||
}
|
||||
if (this.glideOption.errorholderSrc) {
|
||||
request.errorholder(this.glideOption.errorholderSrc, (data) => {
|
||||
this.glideChangeSource(data)
|
||||
this.animateTo('image');
|
||||
})
|
||||
}
|
||||
if (this.glideOption.transformtions) {
|
||||
request.transforms(this.glideOption.transformtions)
|
||||
}
|
||||
if (this.glideOption.dontAnimateFlag) {
|
||||
request.dontAnimate()
|
||||
}
|
||||
|
||||
|
||||
if (this.glideOption.displayProgress) {
|
||||
request.addProgressListener((percentValue: string) => {
|
||||
// 如果进度条百分比 未展示大小,展示其动画
|
||||
this.percent = percentValue;
|
||||
if(this.glideOption.displayProgressListener){
|
||||
this.glideOption.displayProgressListener(percentValue);
|
||||
}
|
||||
this.animateTo('progress');
|
||||
})
|
||||
}
|
||||
|
||||
if(this.glideOption.retryLoad){
|
||||
request.addRetryListener((error: any) => {
|
||||
console.log("RetryListener callback!")
|
||||
this.animateTo('retry');
|
||||
})
|
||||
}
|
||||
}
|
||||
// glide 第一次启动和数据刷新后重新发送请求
|
||||
glideExecute() {
|
||||
let request = new RequestOption();
|
||||
this.configNecessary(request);
|
||||
this.configCacheStrategy(request);
|
||||
this.configDisplay(request);
|
||||
let svgGif = Glide.getSvgAndGifFolder();
|
||||
console.log("输出SVG和gif的缓存地址="+svgGif)
|
||||
console.log("GlideImage Ready to 'call' method! Glide is null="+(Glide == null || Glide == undefined))
|
||||
Glide.call(request);
|
||||
}
|
||||
|
||||
glideChangeSource(data:GlideData) {
|
||||
this.glideSpecialFixed(data);
|
||||
}
|
||||
|
||||
displayPixelMap(data:GlideData){
|
||||
|
||||
this.normalPixelMap = true;
|
||||
this.normalResource = true;
|
||||
let pack = new PixelMapPack();
|
||||
this.glidePixelMapPack = pack;
|
||||
setTimeout(() => {
|
||||
let pixelMapPack2 = new PixelMapPack();
|
||||
pixelMapPack2.pixelMap = data.glideValue as PixelMap;
|
||||
this.glidePixelMapPack = pixelMapPack2;
|
||||
},100)
|
||||
}
|
||||
|
||||
displayResource(data:GlideData){
|
||||
this.normalPixelMap = false;
|
||||
this.normalResource = true;
|
||||
this.glideResource = data.glideValue as Resource;
|
||||
}
|
||||
|
||||
displayString(data:GlideData){
|
||||
|
||||
this.normalPixelMap = false;
|
||||
this.normalResource = false;
|
||||
let firstIndex = (data.glideValue as string).indexOf(Glide.getSvgAndGifFolder());
|
||||
let suffix = (data.glideValue as string).substring(firstIndex, (data.glideValue as string).length)
|
||||
// let glideNeedStr = 'internal://app/' + suffix;
|
||||
let glideNeedStr = 'file://' + data.glideValue;
|
||||
this.glideString = glideNeedStr;
|
||||
|
||||
}
|
||||
glideSpecialFixed(data:GlideData) {
|
||||
if (data.isPixelMap()) {
|
||||
this.displayPixelMap(data);
|
||||
}
|
||||
else if (data.isString()) {
|
||||
this.displayString(data);
|
||||
} else if (data.isResource()) {
|
||||
this.displayResource(data);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
animateTo(name: string) {
|
||||
if (name == 'progress') {
|
||||
this.percentVisible = Visibility.Visible;
|
||||
this.imageVisible = Visibility.Hidden;
|
||||
this.retryVisible = Visibility.Hidden;
|
||||
if (this.percentWidth == '0%' || this.percentHeight == '0%') {
|
||||
animateTo({ duration: this.glideOption.animateDuration , curve: Curve.Linear }, () => {
|
||||
this.percentWidth = '100%';
|
||||
this.percentHeight = '100%';
|
||||
this.imageWidth = '0%';
|
||||
this.imageHeight = '0%';
|
||||
this.retryWidth = '0%';
|
||||
this.retryHeight = '0%';
|
||||
})
|
||||
}
|
||||
} else if (name == 'image') {
|
||||
this.imageVisible = Visibility.Visible;
|
||||
this.percentVisible = Visibility.Hidden;
|
||||
this.retryVisible = Visibility.Hidden;
|
||||
if (this.imageWidth == '0%' || this.imageHeight == '0%') {
|
||||
animateTo({ duration: this.glideOption.animateDuration, curve: Curve.Linear }, () => {
|
||||
this.imageWidth = '100%';
|
||||
this.imageHeight = '100%';
|
||||
this.percentWidth = '0%';
|
||||
this.percentHeight = '0%';
|
||||
this.retryWidth = '0%';
|
||||
this.retryHeight = '0%';
|
||||
})
|
||||
}
|
||||
} else if (name == 'retry') {
|
||||
this.retryVisible = Visibility.Visible;
|
||||
this.imageVisible = Visibility.Hidden;
|
||||
this.percentVisible = Visibility.Hidden;
|
||||
if (this.retryWidth == '0%' || this.retryHeight == '0%') {
|
||||
animateTo({ duration: this.glideOption.animateDuration, curve: Curve.Linear }, () => {
|
||||
this.imageWidth = '0%';
|
||||
this.imageHeight = '0%';
|
||||
this.percentWidth = '0%';
|
||||
this.percentHeight = '0%';
|
||||
this.retryWidth = '100%';
|
||||
this.retryHeight = '100%';
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
}
|
||||
|
||||
onPageShow() {
|
||||
}
|
||||
|
||||
onPageHide() {
|
||||
}
|
||||
|
||||
onBackPress() {
|
||||
}
|
||||
}
|
||||
|
||||
var Glide;
|
||||
var defaultTemp = globalThis.exports.default
|
||||
if (defaultTemp != undefined) {
|
||||
Glide = defaultTemp.data.glide;
|
||||
}
|
|
@ -1,294 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import {DiskStrategy} from "../cache/diskstrategy/DiskStrategy"
|
||||
import {AsyncCallback} from "../glide/interface/asynccallback.ets"
|
||||
import {AsyncSuccess} from "../glide/interface/AsyncSuccess.ets"
|
||||
import {AllCacheInfo, IAllCacheInfoCallback} from "../glide/interface/iallcacheinfocallback.ets"
|
||||
import {AUTOMATIC} from "../cache/diskstrategy/enum/AUTOMATIC"
|
||||
import {BaseTransform} from "../glide/transform/BaseTransform.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {GlideData} from "../glide/GlideData.ets"
|
||||
import fileio from '@ohos.fileio';
|
||||
import image from '@ohos.multimedia.image';
|
||||
import {CenterCrop} from '../glide/transform/pixelmap/CenterCrop.ets'
|
||||
import {CenterInside} from '../glide/transform/pixelmap/CenterInside.ets'
|
||||
import {FitCenter} from '../glide/transform/pixelmap/FitCenter.ets'
|
||||
|
||||
export class RequestOption {
|
||||
loadSrc: string | PixelMap | Resource;
|
||||
strategy: DiskStrategy = new AUTOMATIC();
|
||||
dontAnimateFlag = false;
|
||||
placeholderSrc: PixelMap | Resource;
|
||||
placeholderFunc: AsyncSuccess<GlideData>;
|
||||
errorholderSrc: PixelMap | Resource;
|
||||
errorholderFunc: AsyncSuccess<GlideData>;
|
||||
errorholderData: GlideData;
|
||||
thumbSizeMultiplier: number;
|
||||
|
||||
// 如果存在缩略图,则主图延时3000ms加载
|
||||
thumbDelayTime: number = 3000
|
||||
thumbholderFunc: AsyncSuccess<GlideData>;
|
||||
requestListeners: Array<AsyncCallback<GlideData>>;
|
||||
|
||||
// 进度条
|
||||
progressFunc: AsyncSuccess<string>;
|
||||
|
||||
// 重试图层
|
||||
retryFunc: AsyncSuccess<GlideData>
|
||||
|
||||
// 图层切换时长
|
||||
animateDuraction: number = 500;
|
||||
size: {
|
||||
width: number,
|
||||
height: number
|
||||
} = { width: -1, height: -1 };
|
||||
|
||||
// 网络下载数据回调
|
||||
allCacheInfoCallback: IAllCacheInfoCallback;
|
||||
onlyRetrieveFromCache: boolean = false;
|
||||
isCacheable: boolean = true;
|
||||
|
||||
// 变换相关
|
||||
transformtions: Array<BaseTransform<PixelMap>> = new Array();
|
||||
generateCacheKey: string = "";
|
||||
generateResourceKey: string = "";
|
||||
generateDataKey: string = "";
|
||||
private filesPath: string = ""; // data/data/包名/files目录
|
||||
private cachesPath: string = ""; // 网络下载默认存储在data/data/包名/cache/GlideNetworkFolder/目标md5.img下面
|
||||
|
||||
// 下载原始文件地址
|
||||
downloadFilePath: string = "";
|
||||
|
||||
// 网络文件下载统一存放
|
||||
networkCacheFolder: string = "GlideNetworkFolder"
|
||||
|
||||
|
||||
// 主线图片 状态变化 是否加载完成
|
||||
// 主图未加载成功 显示占位图 主图加载成功不展示占位图
|
||||
loadMainReady = false;
|
||||
|
||||
// 失败占位图展示状态 当true 表示主图加载失败需要展示失败占位图
|
||||
loadErrorReady = false
|
||||
|
||||
// 缩略图展示
|
||||
loadThumbnailReady = false;
|
||||
_svgAndGifFolder: string = "svgAndGifFolder"; // svg和gif的文件路径地址
|
||||
_svgAndGifCommitFile: string = "svgAndGifCommitFile"; // svg和gif提交记录
|
||||
|
||||
constructor() {
|
||||
// 初始化全局监听
|
||||
this.requestListeners = new Array();
|
||||
}
|
||||
|
||||
/**
|
||||
* set image Component size
|
||||
*/
|
||||
setImageViewSize(imageSize: {
|
||||
width: number,
|
||||
height: number
|
||||
}) {
|
||||
this.size.width = imageSize.width;
|
||||
this.size.height = imageSize.height;
|
||||
return this;
|
||||
}
|
||||
|
||||
getFilesPath() {
|
||||
return this.filesPath;
|
||||
}
|
||||
|
||||
setFilesPath(path: string) {
|
||||
this.filesPath = path;
|
||||
}
|
||||
|
||||
getCachesPath() {
|
||||
return this.cachesPath;
|
||||
}
|
||||
|
||||
setCachesPath(path: string) {
|
||||
this.cachesPath = path;
|
||||
}
|
||||
|
||||
load(src: string | PixelMap | Resource) {
|
||||
this.loadSrc = src;
|
||||
return this;
|
||||
}
|
||||
|
||||
diskCacheStrategy(strategy: DiskStrategy) {
|
||||
this.strategy = strategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
dontAnimate() {
|
||||
this.dontAnimateFlag = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
// 仅支持 本地图片
|
||||
placeholder(src: PixelMap | Resource, func?: AsyncSuccess<GlideData>) {
|
||||
this.placeholderSrc = src;
|
||||
this.placeholderFunc = func;
|
||||
return this;
|
||||
}
|
||||
|
||||
errorholder(src: PixelMap | Resource, func?: AsyncSuccess<GlideData>) {
|
||||
this.errorholderSrc = src;
|
||||
this.errorholderFunc = func;
|
||||
return this;
|
||||
}
|
||||
|
||||
thumbnail(sizeMultiplier: number, func?: AsyncSuccess<GlideData>) {
|
||||
this.thumbSizeMultiplier = sizeMultiplier;
|
||||
this.thumbholderFunc = func;
|
||||
return this;
|
||||
}
|
||||
|
||||
addProgressListener(func?: AsyncSuccess<string>) {
|
||||
this.progressFunc = func;
|
||||
return this;
|
||||
}
|
||||
|
||||
addRetryListener(func?: AsyncSuccess<any>) {
|
||||
this.retryFunc = func;
|
||||
return this;
|
||||
}
|
||||
|
||||
addListener(func: AsyncCallback<GlideData>) {
|
||||
this.requestListeners.push(func);
|
||||
return this;
|
||||
}
|
||||
|
||||
addAllCacheInfoCallback(func: IAllCacheInfoCallback) {
|
||||
this.allCacheInfoCallback = func;
|
||||
return this;
|
||||
}
|
||||
|
||||
skipMemoryCache(skip: boolean) {
|
||||
this.isCacheable = !skip;
|
||||
return this;
|
||||
}
|
||||
|
||||
retrieveDataFromCache(flag: boolean) {
|
||||
this.onlyRetrieveFromCache = flag;
|
||||
}
|
||||
|
||||
rotateImage(degreesToRotate: number) {
|
||||
let rotateImage = new RotateImageTransformation(degreesToRotate);
|
||||
this.transformtions.push(rotateImage);
|
||||
return this;
|
||||
}
|
||||
|
||||
centerCrop() {
|
||||
this.transformtions.push(new CenterCrop());
|
||||
return this;
|
||||
}
|
||||
centerInside() {
|
||||
this.transformtions.push(new CenterInside());
|
||||
return this;
|
||||
}
|
||||
fitCenter() {
|
||||
this.transformtions.push(new FitCenter());
|
||||
return this;
|
||||
}
|
||||
|
||||
transform(transform: BaseTransform<PixelMap>) {
|
||||
this.transformtions.push(transform);
|
||||
return this;
|
||||
}
|
||||
|
||||
transforms(transforms: BaseTransform<PixelMap>[]) {
|
||||
this.transformtions = transforms;
|
||||
return this;
|
||||
}
|
||||
|
||||
// 占位图解析成功
|
||||
placeholderOnComplete(glidedata: GlideData) {
|
||||
console.log("placeholderOnComplete has called!");
|
||||
console.log("Main Image is Ready:" + this.loadMainReady);
|
||||
if (!this.loadMainReady && !this.loadErrorReady && !this.loadThumbnailReady) {
|
||||
// 主图未加载成功,并且未加载失败 显示占位图 主图加载成功或者加载失败后=>不展示占位图
|
||||
this.placeholderFunc(glidedata)
|
||||
}
|
||||
}
|
||||
|
||||
// 占位图解析失败
|
||||
placeholderOnError(error) {
|
||||
console.log("占位图解析失败 error =" + error)
|
||||
}
|
||||
|
||||
// 缩略图解析成功
|
||||
thumbholderOnComplete(glidedata: GlideData) {
|
||||
if (!this.loadMainReady && !this.loadErrorReady) {
|
||||
//主图未加载成功,并且未加载失败 显示占位图 主图加载成功或者加载失败后=>不展示占位图
|
||||
this.thumbholderFunc(glidedata)
|
||||
}
|
||||
}
|
||||
|
||||
// 缩略图解析失败
|
||||
thumbholderOnError(error) {
|
||||
console.log("缩略图解析失败 error =" + error)
|
||||
}
|
||||
|
||||
// 加载失败 占位图解析成功
|
||||
errorholderOnComplete(glidedata: GlideData) {
|
||||
// 如果有错误占位图 先解析并保存在RequestOption中 等到加载失败时候进行调用
|
||||
this.errorholderData = glidedata;
|
||||
if (this.loadErrorReady) {
|
||||
this.errorholderFunc(glidedata)
|
||||
}
|
||||
}
|
||||
|
||||
//加载失败 占位图解析失败
|
||||
errorholderOnError(error) {
|
||||
console.log("失败占位图解析失败 error =" + error)
|
||||
}
|
||||
|
||||
loadComplete(glidedata: GlideData) {
|
||||
this.loadMainReady = true;
|
||||
// 三级缓存数据加载成功
|
||||
for (let requestListener of this.requestListeners) {
|
||||
var ret = requestListener("", glidedata);
|
||||
if (ret) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 加载成功之后
|
||||
Glide.removeRunning(this);
|
||||
}
|
||||
|
||||
loadError(err) {
|
||||
console.log("loadError:"+err);
|
||||
//失败占位图展示规则
|
||||
this.loadErrorReady = true;
|
||||
if (this.retryFunc) {
|
||||
// 重试图层优先于加载失败展示
|
||||
this.retryFunc(err)
|
||||
} else {
|
||||
if (this.errorholderData != null) {
|
||||
this.errorholderFunc(this.errorholderData)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载失败之后
|
||||
Glide.removeRunning(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var Glide;
|
||||
var defaultTemp = globalThis.exports.default
|
||||
if (defaultTemp != undefined) {
|
||||
Glide = defaultTemp.data.glide;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
export class PixelEntry {
|
||||
a: number;
|
||||
b: number;
|
||||
r: number;
|
||||
g: number;
|
||||
f: number;
|
||||
pixel: number;
|
||||
|
||||
public toString(): string {
|
||||
return "PixelEntry a:" + this.a + ";b:" + this.b + ";r:" + this.r + ";g:" + this.g + ";f:" + this.f;
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import {IDataFetch} from "../networkmanage/IDataFetch.ets"
|
||||
import {RequestOption} from "../RequestOption.ets"
|
||||
import {Md5} from "../../cache/Md5.ets"
|
||||
import{FileUtils} from "../../cache/FileUtils.ets"
|
||||
|
||||
import httpRequest from '@ohos.request';
|
||||
|
||||
export class DownloadClient implements IDataFetch {
|
||||
loadData(request: RequestOption, onCompleteFunction, onErrorFunction) {
|
||||
|
||||
let requestUrl = request.loadSrc as string;
|
||||
if (requestUrl.startsWith("http") || requestUrl.startsWith("https")) {
|
||||
let filename = Md5.hashStr(request.generateDataKey);
|
||||
let allpath = request.networkCacheFolder + "/" + filename + ".img";
|
||||
var downloadConfig = {
|
||||
url: (request.loadSrc as string),
|
||||
filePath: allpath
|
||||
};
|
||||
httpRequest.download(downloadConfig)
|
||||
.then((downloadTask) => {
|
||||
downloadTask.query((err, data) => {
|
||||
if (err) {
|
||||
onErrorFunction(err)
|
||||
return;
|
||||
}
|
||||
downloadTask.on('progress', (uploadedSize, totalSize)=>{
|
||||
let percent = Math.round(((uploadedSize*1.0)/(totalSize*1.0))*100)+"%"
|
||||
if(request.progressFunc) {
|
||||
request.progressFunc(percent);
|
||||
}
|
||||
});
|
||||
downloadTask.on('complete', () => {
|
||||
let downloadPath = request.getCachesPath() + "/" + allpath;
|
||||
request.downloadFilePath = downloadPath;
|
||||
let arraybuffer = FileUtils.getInstance()
|
||||
.readFilePic(downloadPath)
|
||||
onCompleteFunction(arraybuffer);
|
||||
FileUtils.getInstance()
|
||||
.deleteFile(downloadPath);
|
||||
})
|
||||
downloadTask.on('fail', (err) => {
|
||||
onErrorFunction("DownloadClient Download task fail. err =" + err)
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
onErrorFunction(err)
|
||||
})
|
||||
} else {
|
||||
onErrorFunction("DownloadClient 暂不支持除http之外的uri加载")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import {IDataFetch} from "../networkmanage/IDataFetch.ets"
|
||||
import {RequestOption} from "../RequestOption.ets"
|
||||
import {Md5} from "../../cache/Md5.ets"
|
||||
import {FileUtils} from "../../cache/FileUtils.ets"
|
||||
import {ParseResClient} from "../../glide/resourcemanage/ParseResClient"
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
|
||||
export class SimulatedDownloadClient implements IDataFetch {
|
||||
loadData(request: RequestOption, onCompleteFunction, onErrorFunction) {
|
||||
console.log("SimulatedDownloadClient loadData");
|
||||
let requestUrl = request.loadSrc as string;
|
||||
let resource;
|
||||
//jpg
|
||||
if('https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB' == requestUrl){
|
||||
console.log("SimulatedDownloadClient jpg");
|
||||
resource = $r('app.media.jpgNet')
|
||||
}
|
||||
//png
|
||||
else if('https://img-blog.csdnimg.cn/20191215043500229.png' == requestUrl){
|
||||
console.log("SimulatedDownloadClient png");
|
||||
resource = $r('app.media.pngNet')
|
||||
}
|
||||
//bmp
|
||||
else if('https://img-blog.csdn.net/20140514114029140' == requestUrl){
|
||||
console.log("SimulatedDownloadClient bmp");
|
||||
resource = $r('app.media.bmpNet')
|
||||
}
|
||||
//webp
|
||||
else if('https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp' == requestUrl){
|
||||
console.log("SimulatedDownloadClient webp");
|
||||
resource = $r('app.media.webpNet')
|
||||
}
|
||||
//svg
|
||||
else if('http://design-svc.fat.lunz.cn/StaticFiles/BP9999999772/BV9999999422/SA9999998420/30df266a-485e-411e-b178-b9fb1d8e0748.svg' == requestUrl){
|
||||
console.log("SimulatedDownloadClient svg");
|
||||
resource = $r('app.media.svgNet')
|
||||
}
|
||||
//gif
|
||||
else if('https://pic.ibaotu.com/gif/18/17/16/51u888piCtqj.gif!fwpaa70/fw/700'== requestUrl){
|
||||
console.log("SimulatedDownloadClient gif");
|
||||
resource = $r('app.media.gifNet')
|
||||
}else{
|
||||
new Error("SimulatedDownloadClient not support otherUrl")
|
||||
}
|
||||
|
||||
let resClient = new ParseResClient();
|
||||
resClient.loadResource(resource,(arraybuffer)=>{
|
||||
console.log("SimulatedDownloadClient loadResource callback! ok")
|
||||
if(request.progressFunc) {
|
||||
request.progressFunc("100%")
|
||||
}
|
||||
onCompleteFunction(arraybuffer)
|
||||
},onErrorFunction)
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
import {Closeable} from "/glide/pngj/io/Closeable.ets"
|
||||
import {ImageInfo} from "/glide/pngj/entry/ImageInfo.ets"
|
||||
|
||||
export class PngReader implements Closeable {
|
||||
private static LOG_TAG: string= "PngReader";
|
||||
private static MAX_TOTAL_BYTES_READ_DEFAULT: number= 901001001;
|
||||
private static MAX_BYTES_METADATA_DEFAULT: number= 5024024;
|
||||
private static MAX_CHUNK_SIZE_SKIP: number= 2024024;
|
||||
public imgInfo: ImageInfo;
|
||||
public interlaced: boolean;
|
||||
|
||||
constructor(shouldCloseStream: boolean) {
|
||||
|
||||
}
|
||||
|
||||
close(): void {
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
import {UPNG} from '../pngj/UPNG.js';
|
||||
import image from '@ohos.multimedia.image';
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import featureability from '@ohos.ability.featureAbility'
|
||||
|
||||
export class Pngj {
|
||||
readPngImageInfo(arraybuffer: ArrayBuffer, callback) {
|
||||
let imageSource = image.createImageSource(arraybuffer);
|
||||
imageSource.getImageInfo((err, value) => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
callback(value);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pngBuffer ArrayBuffer containing the PNG file
|
||||
* @param callback
|
||||
* returns an image object with following properties:
|
||||
* width: the width of the image
|
||||
* height: the height of the image
|
||||
* depth: number of bits per channel
|
||||
* ctype: color type of the file (Truecolor, Grayscale, Palette ...)
|
||||
* frames: additional info about frames (frame delays etc.)
|
||||
* tabs: additional chunks of the PNG file
|
||||
* data: pixel data of the image
|
||||
*/
|
||||
readPngImage(pngBuffer: ArrayBuffer, callback) {
|
||||
var png = UPNG.decode(pngBuffer);
|
||||
callback(png)
|
||||
}
|
||||
|
||||
writePngWithString(addInfo:string, pngBuffer: ArrayBuffer,callback) {
|
||||
var pngDecode = UPNG.decode(pngBuffer);
|
||||
var newPng = UPNG.encodeWithString(addInfo, UPNG.toRGBA8(pngDecode), pngDecode.width, pngDecode.height, 0)
|
||||
callback(newPng);
|
||||
}
|
||||
|
||||
writePng(pngBuffer: ArrayBuffer,callback) {
|
||||
var pngDecode = UPNG.decode(pngBuffer);
|
||||
var newPng = UPNG.encode(UPNG.toRGBA8(pngDecode), pngDecode.width, pngDecode.height, 0)
|
||||
callback(newPng);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
export class PngjException extends Error {
|
||||
constructor(s: string) {
|
||||
super(s)
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
export interface IBytesConsumer {
|
||||
isDone(): boolean;
|
||||
|
||||
consume(buf: ArrayBuffer, offset: number, len: number): number;
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
export interface Closeable {
|
||||
close(): void;
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
export class Sandbox {
|
||||
|
||||
|
||||
public static convert(origFileName: string, destFileName: string) {
|
||||
|
||||
}
|
||||
}
|
|
@ -33,11 +33,11 @@ struct BasicTestFeatureAbilityPage {
|
|||
featureAbility.getContext()
|
||||
.getFilesDir()
|
||||
.then((data) => {
|
||||
console.log("Glide filesPath = " + data)
|
||||
console.log("ImageKnife filesPath = " + data)
|
||||
this.filePath = data
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Glide Failed to obtain the filesPath directory. Cause:' + error.message);
|
||||
console.error('ImageKnife Failed to obtain the filesPath directory. Cause:' + error.message);
|
||||
})
|
||||
})
|
||||
Button("featureAbility.getContext().getCacheDir()")
|
||||
|
@ -45,11 +45,11 @@ struct BasicTestFeatureAbilityPage {
|
|||
.onClick(()=>{
|
||||
featureAbility.getContext().getCacheDir()
|
||||
.then((data) => {
|
||||
console.log("Glide cachesPath = " + data)
|
||||
console.log("ImageKnife cachesPath = " + data)
|
||||
this.filePath = data
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Glide Failed to obtain the cachesPath directory. Cause:' + error.message);
|
||||
console.error('ImageKnife Failed to obtain the cachesPath directory. Cause:' + error.message);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import featureAbility from '@ohos.ability.featureAbility';
|
||||
import {FileUtils} from '../cache/FileUtils.ets'
|
||||
import { FileUtils } from '@ohos/imageknife'
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
|
||||
@Entry
|
||||
|
@ -22,6 +22,11 @@ struct BasicTestFileIOPage {
|
|||
@Watch('watchPathChange') @State filePath: string= '查看featureAbility路径';
|
||||
appFilePath = '';
|
||||
appCachePath = '';
|
||||
@State imageFile: string = ''
|
||||
@State imageRes: Resource = $r('app.media.pngSample')
|
||||
@State imagePixelMap: PixelMap = undefined
|
||||
@State normalPixelMap: boolean = false;
|
||||
@State normalResource: boolean = false;
|
||||
|
||||
watchPathChange() {
|
||||
console.log('watchPathChange');
|
||||
|
@ -34,63 +39,91 @@ struct BasicTestFileIOPage {
|
|||
Button('featureAbility.getContext().getFilesDir()')
|
||||
.margin({ top: 10 })
|
||||
.onClick(() => {
|
||||
featureAbility.getContext()
|
||||
.getFilesDir()
|
||||
.then((data) => {
|
||||
console.log('Glide filesPath = ' + data)
|
||||
this.filePath = data
|
||||
this.appFilePath = data;
|
||||
featureAbility.getContext()
|
||||
.getFilesDir()
|
||||
.then((data) => {
|
||||
console.log('ImageKnife filesPath = ' + data)
|
||||
this.filePath = data
|
||||
this.appFilePath = data;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('ImageKnife Failed to obtain the filesPath directory. Cause:' + error.message);
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Glide Failed to obtain the filesPath directory. Cause:' + error.message);
|
||||
})
|
||||
})
|
||||
Button('featureAbility.getContext().getCacheDir()')
|
||||
.margin({ top: 10 })
|
||||
.onClick(() => {
|
||||
featureAbility.getContext()
|
||||
.getCacheDir()
|
||||
.then((data) => {
|
||||
console.log('Glide cachesPath = ' + data)
|
||||
this.filePath = data
|
||||
this.appCachePath = data
|
||||
featureAbility.getContext()
|
||||
.getCacheDir()
|
||||
.then((data) => {
|
||||
console.log('ImageKnife cachesPath = ' + data)
|
||||
this.filePath = data
|
||||
this.appCachePath = data
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('ImageKnife Failed to obtain the cachesPath directory. Cause:' + error.message);
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Glide Failed to obtain the cachesPath directory. Cause:' + error.message);
|
||||
})
|
||||
})
|
||||
Button('files目录创建Folder1和Folder2 验证statSync mkdirSync')
|
||||
.margin({ top: 10 })
|
||||
.onClick(() => {
|
||||
FileUtils.getInstance()
|
||||
.createFolder(this.appFilePath + '/Folder1');
|
||||
FileUtils.getInstance()
|
||||
.createFolder(this.appFilePath + '/Folder2');
|
||||
})
|
||||
FileUtils.getInstance()
|
||||
.createFolder(this.appFilePath + '/Folder1');
|
||||
FileUtils.getInstance()
|
||||
.createFolder(this.appFilePath + '/Folder2');
|
||||
})
|
||||
Button('将media资源存入Folder1 验证writeSync mkdirSync createStreamSync')
|
||||
.margin({ top: 10 })
|
||||
.onClick(() => {
|
||||
resourceManager.getResourceManager()
|
||||
.then(result => {
|
||||
result.getMedia($r('app.media.jpgSample').id, )
|
||||
.then(data => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
|
||||
let arrayBuffer = this.typedArrayToBuffer(data);
|
||||
FileUtils.getInstance().writeFile(this.appFilePath + '/Folder1/jpgSample.jpg',arrayBuffer)
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
resourceManager.getResourceManager()
|
||||
.then(result => {
|
||||
result.getMedia($r('app.media.gifSample').id,)
|
||||
.then(data => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
|
||||
let arrayBuffer = this.typedArrayToBuffer(data);
|
||||
FileUtils.getInstance().writeFile(this.appFilePath + '/Folder1/jpgSample.gif', arrayBuffer)
|
||||
this.imageFile = 'file://' + this.appFilePath + '/Folder1/jpgSample.gif'
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Button('copy:Folder1至Folder2, 验证copyFileSync')
|
||||
.margin({ top: 10 })
|
||||
.onClick(() => {
|
||||
let filePath1 = this.appFilePath + '/Folder1/jpgSample.jpg';
|
||||
let filePath2 = this.appFilePath + '/Folder2/jpgSample.jpg';
|
||||
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder2')
|
||||
FileUtils.getInstance().copyFile(filePath1, filePath2);
|
||||
})
|
||||
let filePath1 = this.appFilePath + '/Folder1/jpgSample.gif';
|
||||
let filePath2 = this.appFilePath + '/Folder2/jpgSample.gif';
|
||||
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder2')
|
||||
FileUtils.getInstance().copyFile(filePath1, filePath2);
|
||||
this.imageFile = 'file://' + this.appFilePath + '/Folder2/jpgSample.gif'
|
||||
})
|
||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Button('显示空PixelMap')
|
||||
.margin({ left: 10 })
|
||||
.onClick(() => {
|
||||
this.normalPixelMap=true;
|
||||
this.normalResource = false;
|
||||
})
|
||||
Button('显示RES')
|
||||
.margin({ left: 10 })
|
||||
.onClick(() => {
|
||||
this.normalPixelMap=false;
|
||||
this.normalResource = true;
|
||||
})
|
||||
Button('显示String')
|
||||
.margin({ left: 10 })
|
||||
.onClick(() => {
|
||||
this.normalPixelMap=false;
|
||||
this.normalResource = false;
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Image(this.normalPixelMap?this.imagePixelMap:(this.normalResource? this.imageRes:this.imageFile))
|
||||
.width(200)
|
||||
.height(200)
|
||||
.backgroundColor(Color.Pink)
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import featureAbility from '@ohos.ability.featureAbility';
|
||||
import {FileUtils} from '../cache/FileUtils.ets'
|
||||
import {FileTypeUtil} from '../glide/utils/FileTypeUtil.ets'
|
||||
import {FileUtils} from '@ohos/imageknife'
|
||||
import {FileTypeUtil} from '@ohos/imageknife'
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import {Base64} from '../cache/Base64.ets'
|
||||
import {PixelMapPack} from '../glide/PixelMapPack.ets'
|
||||
import {ParseImageUtil} from '../glide/utils/ParseImageUtil.ets'
|
||||
import {Base64} from '@ohos/imageknife'
|
||||
import {PixelMapPack} from '@ohos/imageknife'
|
||||
import {ParseImageUtil} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -92,7 +92,7 @@ struct BasicTestMediaImage {
|
|||
.onClick(()=>{
|
||||
resourceManager.getResourceManager()
|
||||
.then(result => {
|
||||
result.getMedia($r('app.media.webpSample').id)
|
||||
result.getMedia($r('app.media.jpgSample').id)
|
||||
.then(data => {
|
||||
let arrayBuffer = this.typedArrayToBuffer(data);
|
||||
let parseImageUtil = new ParseImageUtil();
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import featureAbility from '@ohos.ability.featureAbility';
|
||||
import {FileUtils} from '../cache/FileUtils.ets'
|
||||
import {FileTypeUtil} from '../glide/utils/FileTypeUtil.ets'
|
||||
import {FileUtils} from '@ohos/imageknife'
|
||||
import {FileTypeUtil} from '@ohos/imageknife'
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import {Base64} from '../cache/Base64.ets'
|
||||
import {Base64} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
|
|
@ -1,7 +1,21 @@
|
|||
import {Glide} from '../glide/Glide.ets'
|
||||
import {PixelMapPack} from '../glide/PixelMapPack.ets'
|
||||
import {OnRenameListener} from '../glide/compress/listener/OnRenameListener.ets'
|
||||
import {OnCompressListener} from '../glide/compress/listener/OnCompressListener.ets'
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
import {ImageKnife} from '@ohos/imageknife'
|
||||
import {PixelMapPack} from '@ohos/imageknife'
|
||||
import {OnRenameListener} from '@ohos/imageknife'
|
||||
import {OnCompressListener} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -83,7 +97,7 @@ struct CompressPage {
|
|||
data.push($r('app.media.jpgSample'))
|
||||
|
||||
console.info("asasd start compress")
|
||||
Glide.with()
|
||||
ImageKnife.with()
|
||||
.compressBuilder()
|
||||
.load(data)
|
||||
.ignoreBy(100)
|
||||
|
@ -123,7 +137,7 @@ struct CompressPage {
|
|||
}
|
||||
}
|
||||
console.info("asasd start compress")
|
||||
Glide.with()
|
||||
ImageKnife.with()
|
||||
.compressBuilder()
|
||||
.load(data)
|
||||
.ignoreBy(100)
|
|
@ -13,11 +13,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {CropImage} from '../glide/crop/CropImage.ets'
|
||||
import {CropOptions} from '../glide/crop/CropOptions.ets'
|
||||
import {Crop} from '../glide/crop/Crop.ets'
|
||||
import {RecourseProvider} from '../glide/compress/provider/RecourseProvider.ets'
|
||||
import {PixelMapPack} from "../glide/PixelMapPack.ets";
|
||||
import {CropImage} from '@ohos/imageknife'
|
||||
import {CropOptions} from '@ohos/imageknife'
|
||||
import {Crop} from '@ohos/imageknife'
|
||||
import {RecourseProvider} from '@ohos/imageknife'
|
||||
import {PixelMapPack} from '@ohos/imageknife'
|
||||
|
||||
|
||||
@Component
|
|
@ -12,10 +12,10 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from "../glide/GlideImage.ets"
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {RoundedCornersTransformation} from "../glide/transform/RoundedCornersTransformation.ets"
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
import {RoundedCornersTransformation} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -24,7 +24,7 @@ struct FrescoImageTestCasePage {
|
|||
@State progresshint:string = "输出加载百分比回调信息"
|
||||
|
||||
|
||||
@State glideOption1: GlideOption =
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83ericA1Mv66TwicuYOtbDMBcUhv1aa9RJBeAn9uURfcZD0AUGrJebAn1g2AjN0vb2E1XTET7fTuLBNmA/132",
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -32,7 +32,7 @@ struct FrescoImageTestCasePage {
|
|||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
displayProgress: true
|
||||
};
|
||||
@State glideOption2: GlideOption =
|
||||
@State imageKnifeOption2: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/0ef60041445edcfd6b38d20e19024b2cd9281dcc3525a4-Vy8fYO_fw658/format/webp",
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -40,7 +40,7 @@ struct FrescoImageTestCasePage {
|
|||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
displayProgress: true
|
||||
};
|
||||
@State glideOption3: GlideOption =
|
||||
@State imageKnifeOption3: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp",
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -48,7 +48,7 @@ struct FrescoImageTestCasePage {
|
|||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
displayProgress: true
|
||||
};
|
||||
@State glideOption4: GlideOption =
|
||||
@State imageKnifeOption4: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -65,10 +65,10 @@ struct FrescoImageTestCasePage {
|
|||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
// GlideImage({ glideOption: $glideOption1 })
|
||||
// GlideImage({ glideOption: $glideOption2 })
|
||||
// GlideImage({ glideOption: $glideOption3 })
|
||||
GlideImage({ glideOption: $glideOption4 })
|
||||
// ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
// ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption2 })
|
||||
// ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption3 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption4 })
|
||||
Scroll() {
|
||||
Text(this.progresshint).fontSize(15)
|
||||
}.width(300).height(200)
|
||||
|
|
|
@ -12,15 +12,15 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from "../glide/GlideImage.ets"
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {RoundedCornersTransformation} from "../glide/transform/RoundedCornersTransformation.ets"
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
import {RoundedCornersTransformation} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct FrescoImageTestCasePage {
|
||||
@State glideOption1: GlideOption =
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83ericA1Mv66TwicuYOtbDMBcUhv1aa9RJBeAn9uURfcZD0AUGrJebAn1g2AjN0vb2E1XTET7fTuLBNmA/132",
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -30,7 +30,7 @@ struct FrescoImageTestCasePage {
|
|||
animateDuration: 300,
|
||||
retryLoad:true
|
||||
};
|
||||
@State glideOption2: GlideOption =
|
||||
@State imageKnifeOption2: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/0ef60041445edcfd6b38d20e19024b2cd9281dcc3525a4-Vy8fYO_fw658/format/webp",
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -40,7 +40,7 @@ struct FrescoImageTestCasePage {
|
|||
animateDuration: 300,
|
||||
retryLoad:true
|
||||
};
|
||||
@State glideOption3: GlideOption =
|
||||
@State imageKnifeOption3: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp",
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -50,7 +50,7 @@ struct FrescoImageTestCasePage {
|
|||
animateDuration: 300,
|
||||
retryLoad:true
|
||||
};
|
||||
@State glideOption4: GlideOption =
|
||||
@State imageKnifeOption4: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/testRetryxxxx",
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -64,10 +64,10 @@ struct FrescoImageTestCasePage {
|
|||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
// GlideImage({ glideOption: $glideOption1 })
|
||||
// GlideImage({ glideOption: $glideOption2 })
|
||||
// GlideImage({ glideOption: $glideOption3 })
|
||||
GlideImage({ glideOption: $glideOption4 })
|
||||
// ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
// ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption2 })
|
||||
// ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption3 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption4 })
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import router from '@system.router';
|
||||
import {Pngj} from '../glide/pngj/Pngj'
|
||||
import {SimulatedDownloadClient} from '../glide/networkmanage/SimulatedDownloadClient'
|
||||
import {Pngj} from '@ohos/imageknife'
|
||||
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -23,12 +23,6 @@ struct Index {
|
|||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Button(this.hint1).fontSize(15)
|
||||
.onClick(()=>{
|
||||
let simulatedDownloadClient = new SimulatedDownloadClient();
|
||||
Glide.replaceDataFetch(simulatedDownloadClient)
|
||||
this.hint1 = '已启用网络模拟加载替换网络加载'
|
||||
})
|
||||
Text("OHOS基础接口测试列表").fontSize(15)
|
||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Button("测试元能力")
|
||||
|
@ -64,14 +58,15 @@ struct Index {
|
|||
}).margin({ top: 5, left: 3 })
|
||||
Button("测试图片切换")
|
||||
.onClick(() => {
|
||||
console.log("测试GlideImage所有图片切换")
|
||||
router.push({ uri: "pages/testGlideOptionChangedPage" });
|
||||
console.log("测试ImageKnifeComponent所有图片切换")
|
||||
router.push({ uri: "pages/testImageKnifeOptionChangedPage" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
Button("测试thumbnail")
|
||||
.onClick(() => {
|
||||
console.log("测试GlideImage thumbnail")
|
||||
router.push({ uri: "pages/testGlideOptionChangedPage2" });
|
||||
console.log("测试ImageKnifeComponent thumbnail")
|
||||
router.push({ uri: "pages/testImageKnifeOptionChangedPage2" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
|
||||
}.width('100%')
|
||||
.height(60).backgroundColor(Color.Pink)
|
||||
|
||||
|
@ -87,11 +82,7 @@ struct Index {
|
|||
console.log("测试二级内存缓存")
|
||||
router.push({ uri: "pages/storageTestDiskLruCache" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
Button("测试JPEG")
|
||||
.onClick(() => {
|
||||
console.log("测试JPEG")
|
||||
router.push({ uri: "pages/JpegProgressTestCasePage" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
|
||||
}.width('100%')
|
||||
.height(60).backgroundColor(Color.Pink)
|
||||
|
||||
|
@ -130,12 +121,12 @@ struct Index {
|
|||
Button("测试图片变换")
|
||||
.onClick(() => {
|
||||
console.log("测试图片变换")
|
||||
router.push({ uri: "pages/TransformPixelMapPage" });
|
||||
router.push({ uri: "pages/transformPixelMapPage" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
Button("测试图片压缩")
|
||||
.onClick(() => {
|
||||
console.log("测试图片压缩")
|
||||
router.push({ uri: "pages/CompressPage" });
|
||||
router.push({ uri: "pages/compressPage" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
}.width('100%')
|
||||
.height(60).backgroundColor(Color.Pink)
|
||||
|
@ -159,14 +150,10 @@ struct Index {
|
|||
}).margin({ top: 15 })
|
||||
Button("测试图片的裁剪")
|
||||
.onClick(() => {
|
||||
console.log("pages/CropImagePage 页面跳转")
|
||||
router.push({ uri: "pages/CropImagePage" });
|
||||
}).margin({ top: 15 })
|
||||
Button("测试网络")
|
||||
.onClick(() => {
|
||||
console.log("pages/networkTestCasePage 页面跳转")
|
||||
router.push({ uri: "pages/networkTestCasePage" });
|
||||
console.log("pages/cropImagePage 页面跳转")
|
||||
router.push({ uri: "pages/cropImagePage" });
|
||||
}).margin({ top: 15 })
|
||||
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
|
@ -177,12 +164,12 @@ struct Index {
|
|||
}
|
||||
|
||||
onBackPress() {
|
||||
let cache = Glide.getMemoryCache();
|
||||
let cache = ImageKnife.getMemoryCache();
|
||||
cache.print()
|
||||
}
|
||||
}
|
||||
var Glide;
|
||||
var ImageKnife;
|
||||
var defaultTemp = globalThis.exports.default
|
||||
if (defaultTemp != undefined) {
|
||||
Glide = defaultTemp.data.glide;
|
||||
ImageKnife = defaultTemp.data.imageKnife;
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
import {GlideImage} from "../glide/GlideImage.ets"
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {FileUtils} from "../cache/FileUtils.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {RoundedCornersTransformation} from "../glide/transform/RoundedCornersTransformation.ets"
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import image from "@ohos.multimedia.image"
|
||||
@Entry
|
||||
@Component
|
||||
struct JpegProgressTestCasePage {
|
||||
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Button('点击调用渐进式解码')
|
||||
.onClick(()=> {
|
||||
resourceManager.getResourceManager()
|
||||
.then(result => {
|
||||
result.getMedia($r('app.media.jpgSample').id)
|
||||
.then(data => {
|
||||
let arrayBuffer = FileUtils.getInstance().uint8ArrayToBuffer(data);
|
||||
let imageSourceIncrementalSApi = image.createIncrementalSource(data);
|
||||
let array = [1,2,3,4,5,6,7,8,9,10];
|
||||
imageSourceIncrementalSApi.updateData(array, false,(error,data) => {
|
||||
console.log("data is null="+(data == null || data == undefined))
|
||||
console.log("array = "+array)
|
||||
console.log("data ="+data)
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
Button('点击调用渐进式解码带上length')
|
||||
.onClick(()=> {
|
||||
resourceManager.getResourceManager()
|
||||
.then(result => {
|
||||
result.getMedia($r('app.media.jpgSample').id)
|
||||
.then(data => {
|
||||
let arrayBuffer = FileUtils.getInstance().uint8ArrayToBuffer(data);
|
||||
let imageSourceIncrementalSApi = image.createIncrementalSource(data);
|
||||
let array = [1,2,3,4,5,6,7,8,9,10];
|
||||
imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error,data) => {
|
||||
console.log("data is null="+(data == null || data == undefined))
|
||||
console.log("array = "+array)
|
||||
console.log("data ="+data)
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
|
|
@ -12,36 +12,36 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from "../glide/GlideImage.ets"
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {RoundedCornersTransformation} from "../glide/transform/RoundedCornersTransformation.ets"
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
import {RoundedCornersTransformation} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct LoadNetworkTestCasePage {
|
||||
@State glideOption1: GlideOption =
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83ericA1Mv66TwicuYOtbDMBcUhv1aa9RJBeAn9uURfcZD0AUGrJebAn1g2AjN0vb2E1XTET7fTuLBNmA/132",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
};
|
||||
@State glideOption2: GlideOption =
|
||||
@State imageKnifeOption2: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/0ef60041445edcfd6b38d20e19024b2cd9281dcc3525a4-Vy8fYO_fw658/format/webp",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
};
|
||||
@State glideOption3: GlideOption =
|
||||
@State imageKnifeOption3: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
};
|
||||
@State glideOption4: GlideOption =
|
||||
@State imageKnifeOption4: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -52,10 +52,10 @@ struct LoadNetworkTestCasePage {
|
|||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
GlideImage({ glideOption: $glideOption1 })
|
||||
GlideImage({ glideOption: $glideOption2 })
|
||||
GlideImage({ glideOption: $glideOption3 })
|
||||
GlideImage({ glideOption: $glideOption4 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption2 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption3 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption4 })
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
|
|
|
@ -12,36 +12,36 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from "../glide/GlideImage.ets"
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {RoundedCornersTransformation} from "../glide/transform/RoundedCornersTransformation.ets"
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
import {RoundedCornersTransformation} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct LoadResourceTestCasePage {
|
||||
@State glideOption1: GlideOption =
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.gifSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
};
|
||||
@State glideOption2: GlideOption =
|
||||
@State imageKnifeOption2: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.bmpSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
// placeholderSrc: $r('app.media.icon_loading'),
|
||||
// errorholderSrc: $r('app.media.icon_failed'),
|
||||
};
|
||||
@State glideOption3: GlideOption =
|
||||
@State imageKnifeOption3: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
// placeholderSrc: $r('app.media.icon_loading'),
|
||||
// errorholderSrc: $r('app.media.icon_failed'),
|
||||
};
|
||||
@State glideOption4: GlideOption =
|
||||
@State imageKnifeOption4: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -52,10 +52,10 @@ struct LoadResourceTestCasePage {
|
|||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
GlideImage({ glideOption: $glideOption1 })
|
||||
// GlideImage({ glideOption: $glideOption2 })
|
||||
// GlideImage({ glideOption: $glideOption3 })
|
||||
// GlideImage({ glideOption: $glideOption4 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
// ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption2 })
|
||||
// ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption3 })
|
||||
// ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption4 })
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
|
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 1521 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 router from '@system.router';
|
||||
|
||||
import request from '@ohos.requestability';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct NetworkTestCasePage {
|
||||
@State hint1: string = '基础request'
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Button('网络上传下载1').fontSize(15)
|
||||
.margin({ top: 30 })
|
||||
.onClick(() => {
|
||||
console.log("网络上传下载1")
|
||||
|
||||
let DownloadConfig = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/libs/libc5/libc5.cvs.tar.gz', // Resource address.
|
||||
header: {}, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/data/abc1.txt', // Sets the path for downloads.
|
||||
title: 'a', // Sets a download session title.
|
||||
}
|
||||
|
||||
let downloadTask;
|
||||
|
||||
// 使用callback形式回调返回DownloadTask实例。
|
||||
console.log("------------------start Download_Test_0100-------------------");
|
||||
try {
|
||||
console.log("Show me the log");
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
console.log("Download_Test_0100: register download issue successful, result = " + data);
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("logMessage Download_Test_0100: error = " + error);
|
||||
}
|
||||
console.log("------------------end Download_Test_0100-------------------");
|
||||
})
|
||||
|
||||
Button('网络上传下载2').fontSize(15)
|
||||
.margin({ top: 30 })
|
||||
.onClick(() => {
|
||||
console.log("网络上传下载2")
|
||||
let downloadConfig = {
|
||||
url: 'https://img-blog.csdn.net/20140514114029140',
|
||||
header: {},
|
||||
enableMetered: true,
|
||||
enableRoaming: true,
|
||||
description: 'download libc from mirror site',
|
||||
networkType: 1,
|
||||
filePath: '/data/bmpSample.bmp',
|
||||
title: 'download libc',
|
||||
}
|
||||
let downloadTask;
|
||||
// 使用callback形式回调返回DownloadTask实例。
|
||||
console.log("------------------start Download_Test_0102-------------------");
|
||||
try {
|
||||
console.log("Show me the log");
|
||||
request.download(downloadConfig, (err, data) => {
|
||||
console.log("Download_Test_0102: register download issue successful, result = " + data);
|
||||
data.on('complete',(err1,data1) =>{
|
||||
console.log("Download_Test_0700: , on complete result = "+data1);
|
||||
})
|
||||
data.on('eventType',(err1,data1,data2) =>{
|
||||
console.log("Download_Test_0200: , on progress result data1 = "+data1);
|
||||
console.log("Download_Test_0200: , on progress result data2 = "+data2);
|
||||
})
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("logMessage Download_Test_0102: error = " + error);
|
||||
}
|
||||
console.log("------------------end Download_Test_0102-------------------");
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
}
|
||||
|
||||
onBackPress() {
|
||||
let cache = Glide.getMemoryCache();
|
||||
cache.print()
|
||||
}
|
||||
}
|
||||
|
||||
var Glide;
|
||||
var defaultTemp = globalThis.exports.default
|
||||
if (defaultTemp != undefined) {
|
||||
Glide = defaultTemp.data.glide;
|
||||
}
|
|
@ -13,11 +13,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import router from '@system.router';
|
||||
import {Pngj} from '../glide/pngj/Pngj'
|
||||
import {Pngj} from '@ohos/imageknife'
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import {FileUtils} from '../cache/FileUtils.ets'
|
||||
import {FileUtils} from '@ohos/imageknife'
|
||||
import featureability from '@ohos.ability.featureAbility'
|
||||
|
||||
import ArkWorker from '@ohos.worker'
|
||||
@Entry
|
||||
@Component
|
||||
struct PngjTestCasePage {
|
||||
|
@ -63,14 +63,14 @@ struct PngjTestCasePage {
|
|||
Button('测试readPngImageInfo')
|
||||
.onClick(() => {
|
||||
let pngj = new Pngj();
|
||||
pngj.readPngImageInfo(this.pngSource, (value) => {
|
||||
pngj.readPngImageInfo(this.pngSource, (sender, value) => {
|
||||
this.hint1 = JSON.stringify(value);
|
||||
})
|
||||
}).margin({ top: 5, left: 10 })
|
||||
Button('测试readPngImage')
|
||||
.onClick(() => {
|
||||
let pngj = new Pngj();
|
||||
pngj.readPngImage(this.pngSource, (value) => {
|
||||
pngj.readPngImage(this.pngSource, (sender, value) => {
|
||||
this.hint2 = 'img with=' + value.width + ' img height=' + value.height
|
||||
+ ' img depth=' + value.depth + ' img ctype=' + value.ctype
|
||||
console.log('png data =' + value.data);
|
||||
|
@ -79,7 +79,7 @@ struct PngjTestCasePage {
|
|||
Button('测试writePngWithString')
|
||||
.onClick(() => {
|
||||
let pngj = new Pngj();
|
||||
pngj.writePngWithString('hello world', this.pngSource, (value) => {
|
||||
pngj.writePngWithString('hello world', this.pngSource, (sender, value) => {
|
||||
|
||||
FileUtils.getInstance().createFileProcess(
|
||||
this.rootFolder + '/pngj',
|
||||
|
@ -92,7 +92,55 @@ struct PngjTestCasePage {
|
|||
Button('测试writePng')
|
||||
.onClick(() => {
|
||||
let pngj = new Pngj();
|
||||
pngj.writePng(this.pngSource, (value) => {
|
||||
pngj.writePng(this.pngSource, (sender, value) => {
|
||||
FileUtils.getInstance().createFileProcess(
|
||||
this.rootFolder + '/pngj',
|
||||
this.rootFolder + '/pngj/newPng2.png',
|
||||
value)
|
||||
let png2 = new Uint8Array(value)
|
||||
this.hint4 = 'png2未写入长度' + png2.byteLength + '目录文件:' + this.rootFolder + '/pngj/newPng2.png' + '保存后使用2进制查看数据是否新增'
|
||||
})
|
||||
}).margin({ top: 5, left: 10 })
|
||||
}.width('100%')
|
||||
.height(60).backgroundColor(Color.Pink)
|
||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Button('测试readPngImageInfo')
|
||||
.onClick(() => {
|
||||
let pngj = new Pngj();
|
||||
pngj.readPngImageInfo(this.pngSource, (sender, value) => {
|
||||
this.hint1 = JSON.stringify(value);
|
||||
})
|
||||
}).margin({ top: 5, left: 10 })
|
||||
Button('测试readPngImageAsync')
|
||||
.onClick(() => {
|
||||
let pngj = new Pngj();
|
||||
let worker = new ArkWorker.Worker('workers/worker1.js', { type: 'classic', name: 'readPngImageAsync'})
|
||||
pngj.readPngImageAsync(worker, this.pngSource, (sender, value) => {
|
||||
this.pngSource = sender
|
||||
this.hint2 = 'img with=' + value.width + ' img height=' + value.height
|
||||
+ ' img depth=' + value.depth + ' img ctype=' + value.ctype
|
||||
})
|
||||
}).margin({ top: 5, left: 10 })
|
||||
Button('测试writePngWithStringAsync')
|
||||
.onClick(() => {
|
||||
let pngj = new Pngj();
|
||||
let worker = new ArkWorker.Worker('workers/worker1.js', { type: 'classic', name: 'writePngWithStringAsync'})
|
||||
pngj.writePngWithStringAsync(worker, 'hello world', this.pngSource, (sender, value) => {
|
||||
this.pngSource = sender
|
||||
FileUtils.getInstance().createFileProcess(
|
||||
this.rootFolder + '/pngj',
|
||||
this.rootFolder + '/pngj/newPng.png',
|
||||
value)
|
||||
let png1 = new Uint8Array(value)
|
||||
this.hint3 = 'png写入后长度' + png1.byteLength + '目录文件:' + this.rootFolder + '/pngj/newPng.png' + '保存后使用2进制查看数据是否新增'
|
||||
})
|
||||
}).margin({ top: 5, left: 10 })
|
||||
Button('测试writePngAsync')
|
||||
.onClick(() => {
|
||||
let pngj = new Pngj();
|
||||
let worker = new ArkWorker.Worker('workers/worker1.js', { type: 'classic', name: 'writePngAsync'})
|
||||
pngj.writePngAsync(worker, this.pngSource, (sender, value) => {
|
||||
this.pngSource = sender
|
||||
FileUtils.getInstance().createFileProcess(
|
||||
this.rootFolder + '/pngj',
|
||||
this.rootFolder + '/pngj/newPng2.png',
|
||||
|
@ -126,5 +174,3 @@ struct PngjTestCasePage {
|
|||
return array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset)
|
||||
}
|
||||
}
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
|
@ -12,36 +12,36 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from "../glide/GlideImage.ets"
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {RoundedCornersTransformation} from "../glide/transform/RoundedCornersTransformation.ets"
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
import {RoundedCornersTransformation} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct ShowErrorholderTestCasePage {
|
||||
@State glideOption1: GlideOption =
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://thirdwx.qlogo.cn/mmopen/xxxxx",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
};
|
||||
@State glideOption2: GlideOption =
|
||||
@State imageKnifeOption2: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/xxxxx",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
};
|
||||
@State glideOption3: GlideOption =
|
||||
@State imageKnifeOption3: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/xxxxx",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
};
|
||||
@State glideOption4: GlideOption =
|
||||
@State imageKnifeOption4: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://hbimg.huabanimg.com/xxxxx",
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -52,10 +52,10 @@ struct ShowErrorholderTestCasePage {
|
|||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
GlideImage({ glideOption: $glideOption1 })
|
||||
GlideImage({ glideOption: $glideOption2 })
|
||||
GlideImage({ glideOption: $glideOption3 })
|
||||
GlideImage({ glideOption: $glideOption4 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption2 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption3 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption4 })
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
*/
|
||||
|
||||
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {RequestOption} from "../glide/RequestOption.ets"
|
||||
import {GlideData} from "../glide/GlideData.ets"
|
||||
import {PixelMapPack} from "../glide/PixelMapPack.ets"
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RequestOption} from '@ohos/imageknife'
|
||||
import {ImageKnifeData} from '@ohos/imageknife'
|
||||
import {PixelMapPack} from '@ohos/imageknife'
|
||||
|
||||
|
||||
|
||||
|
@ -25,46 +25,46 @@ import {PixelMapPack} from "../glide/PixelMapPack.ets"
|
|||
@Entry
|
||||
@Component
|
||||
struct StorageTestDiskLruCache {
|
||||
@Watch('watchGlideOption') @State glideOption: GlideOption =
|
||||
@Watch('watchImageKnifeOption') @State imageKnifeOption: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
};
|
||||
@State glidePixelMapPack: PixelMapPack = new PixelMapPack();
|
||||
@State glideResource: Resource = $r('app.media.icon_loading')
|
||||
@State glideString: string = ""
|
||||
@State imageKnifePixelMapPack: PixelMapPack = new PixelMapPack();
|
||||
@State imageKnifeResource: Resource = $r('app.media.icon_loading')
|
||||
@State imageKnifeString: string = ""
|
||||
@State normalPixelMap: boolean = false;
|
||||
@State normalResource: boolean = true;
|
||||
previousData: GlideData = null;
|
||||
nowData: GlideData = null;
|
||||
previousData: ImageKnifeData = null;
|
||||
nowData: ImageKnifeData = null;
|
||||
@State logText: string = "打印日志结果";
|
||||
|
||||
|
||||
watchGlideOption() {
|
||||
this.glideExecute();
|
||||
watchImageKnifeOption() {
|
||||
this.imageKnifeExecute();
|
||||
}
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Text("Glide测试DiskLruCache能力")
|
||||
Text("ImageKnife测试DiskLruCache能力")
|
||||
.backgroundColor(Color.Blue)
|
||||
Button("替换Glide默认DiskLruCache并设置大小1M")
|
||||
Button("替换ImageKnife默认DiskLruCache并设置大小1M")
|
||||
.onClick(() => {
|
||||
diskGlide.replaceDiskLruCache(1 * 1024 * 1024)
|
||||
DiskImageKnife.replaceDiskLruCache(1 * 1024 * 1024)
|
||||
}).margin({top:15, bottom:15})
|
||||
|
||||
Button("替换Glide默认DiskLruCache并设置大小30M")
|
||||
Button("替换ImageKnife默认DiskLruCache并设置大小30M")
|
||||
.onClick(() => {
|
||||
diskGlide.replaceDiskLruCache(30 * 1024 * 1024)
|
||||
DiskImageKnife.replaceDiskLruCache(30 * 1024 * 1024)
|
||||
}).margin({top:15, bottom:15})
|
||||
|
||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Button("加载jpg网络图")
|
||||
.onClick(() => {
|
||||
this.glideOption = {
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -75,7 +75,7 @@ struct StorageTestDiskLruCache {
|
|||
}).margin({ top: 5, left: 10 })
|
||||
Button("加载png网络图")
|
||||
.onClick(() => {
|
||||
this.glideOption = {
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: "https://img-blog.csdnimg.cn/20191215043500229.png",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -85,7 +85,7 @@ struct StorageTestDiskLruCache {
|
|||
}).margin({ top: 5, left: 10 })
|
||||
Button("加载webp网络图")
|
||||
.onClick(() => {
|
||||
this.glideOption = {
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: "https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -95,7 +95,7 @@ struct StorageTestDiskLruCache {
|
|||
}).margin({ top: 5, left: 10 })
|
||||
Button("加载bmp网络图")
|
||||
.onClick(() => {
|
||||
this.glideOption = {
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: "https://img-blog.csdn.net/20140514114029140",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -107,12 +107,12 @@ struct StorageTestDiskLruCache {
|
|||
.height(60).backgroundColor(Color.Pink)
|
||||
|
||||
|
||||
Image(this.normalPixelMap ? this.glidePixelMapPack.pixelMap : (this.normalResource ? this.glideResource : this.glideString))
|
||||
.width(this.glideOption.size ? this.glideOption.size.width : '100%')
|
||||
.height(this.glideOption.size ? this.glideOption.size.height : '100%')
|
||||
.objectFit(this.glideOption.imageFit ? this.glideOption.imageFit : ImageFit.Fill)
|
||||
.backgroundColor(this.glideOption.backgroundColor ? this.glideOption.backgroundColor : Color.White)
|
||||
.margin(this.glideOption.margin ? this.glideOption.margin : { left: 0, top: 0, right: 0, bottom: 0 })
|
||||
Image(this.normalPixelMap ? this.imageKnifePixelMapPack.pixelMap : (this.normalResource ? this.imageKnifeResource : this.imageKnifeString))
|
||||
.width(this.imageKnifeOption.size ? this.imageKnifeOption.size.width : '100%')
|
||||
.height(this.imageKnifeOption.size ? this.imageKnifeOption.size.height : '100%')
|
||||
.objectFit(this.imageKnifeOption.imageFit ? this.imageKnifeOption.imageFit : ImageFit.Fill)
|
||||
.backgroundColor(this.imageKnifeOption.backgroundColor ? this.imageKnifeOption.backgroundColor : Color.White)
|
||||
.margin(this.imageKnifeOption.margin ? this.imageKnifeOption.margin : { left: 0, top: 0, right: 0, bottom: 0 })
|
||||
|
||||
|
||||
|
||||
|
@ -128,59 +128,56 @@ struct StorageTestDiskLruCache {
|
|||
}
|
||||
|
||||
|
||||
// glide 第一次启动和数据刷新后重新发送请求
|
||||
glideExecute() {
|
||||
// imageKnife 第一次启动和数据刷新后重新发送请求
|
||||
imageKnifeExecute() {
|
||||
let request = new RequestOption();
|
||||
request.load(this.glideOption.loadSrc)
|
||||
request.load(this.imageKnifeOption.loadSrc)
|
||||
.addListener((err, data) => {
|
||||
this.glideChangeSource(data)
|
||||
this.imageKnifeChangeSource(data)
|
||||
return false;
|
||||
})
|
||||
if (this.glideOption.placeholderSrc) {
|
||||
request.placeholder(this.glideOption.placeholderSrc, (data) => {
|
||||
this.glideChangeSource(data)
|
||||
if (this.imageKnifeOption.placeholderSrc) {
|
||||
request.placeholder(this.imageKnifeOption.placeholderSrc, (data) => {
|
||||
this.imageKnifeChangeSource(data)
|
||||
})
|
||||
}
|
||||
if (this.glideOption.errorholderSrc) {
|
||||
request.errorholder(this.glideOption.errorholderSrc, (data) => {
|
||||
this.glideChangeSource(data)
|
||||
if (this.imageKnifeOption.errorholderSrc) {
|
||||
request.errorholder(this.imageKnifeOption.errorholderSrc, (data) => {
|
||||
this.imageKnifeChangeSource(data)
|
||||
})
|
||||
}
|
||||
if (this.glideOption.transformtions) {
|
||||
request.transforms(this.glideOption.transformtions)
|
||||
|
||||
if (this.imageKnifeOption.size) {
|
||||
request.setImageViewSize(this.imageKnifeOption.size)
|
||||
}
|
||||
|
||||
if (this.glideOption.size) {
|
||||
request.setImageViewSize(this.glideOption.size)
|
||||
if (this.imageKnifeOption.onlyRetrieveFromCache) {
|
||||
request.retrieveDataFromCache(this.imageKnifeOption.onlyRetrieveFromCache)
|
||||
}
|
||||
|
||||
if (this.glideOption.onlyRetrieveFromCache) {
|
||||
request.retrieveDataFromCache(this.glideOption.onlyRetrieveFromCache)
|
||||
if (this.imageKnifeOption.isCacheable) {
|
||||
request.skipMemoryCache(!this.imageKnifeOption.isCacheable)
|
||||
}
|
||||
|
||||
if (this.glideOption.isCacheable) {
|
||||
request.skipMemoryCache(!this.glideOption.isCacheable)
|
||||
if (this.imageKnifeOption.strategy) {
|
||||
request.diskCacheStrategy(this.imageKnifeOption.strategy)
|
||||
}
|
||||
|
||||
if (this.glideOption.strategy) {
|
||||
request.diskCacheStrategy(this.glideOption.strategy)
|
||||
}
|
||||
|
||||
if (this.glideOption.dontAnimateFlag) {
|
||||
if (this.imageKnifeOption.dontAnimateFlag) {
|
||||
request.dontAnimate()
|
||||
}
|
||||
if (this.glideOption.allCacheInfoCallback) {
|
||||
request.addAllCacheInfoCallback(this.glideOption.allCacheInfoCallback)
|
||||
if (this.imageKnifeOption.allCacheInfoCallback) {
|
||||
request.addAllCacheInfoCallback(this.imageKnifeOption.allCacheInfoCallback)
|
||||
}
|
||||
|
||||
diskGlide.call(request);
|
||||
DiskImageKnife.call(request);
|
||||
}
|
||||
|
||||
glideChangeSource(data:GlideData) {
|
||||
this.glideSpecialFixed(data);
|
||||
imageKnifeChangeSource(data:ImageKnifeData) {
|
||||
this.imageKnifeSpecialFixed(data);
|
||||
|
||||
//查看mGlide中的DiskLruCache
|
||||
let disk = diskGlide.getDiskMemoryCache();
|
||||
//查看mImageKnife中的DiskLruCache
|
||||
let disk = DiskImageKnife.getDiskMemoryCache();
|
||||
let showDisk = ''
|
||||
disk.foreachDiskLruCache((value, key, map) => {
|
||||
showDisk += "key=" + key + "&value=" + value;
|
||||
|
@ -188,115 +185,114 @@ struct StorageTestDiskLruCache {
|
|||
this.logText = "日志结果:" + showDisk;
|
||||
}
|
||||
|
||||
glideSpecialFixed(data:GlideData) {
|
||||
imageKnifeSpecialFixed(data:ImageKnifeData) {
|
||||
if (this.nowData) {
|
||||
this.previousData = this.nowData;
|
||||
this.nowData = data;
|
||||
if (data.isPixelMap()) {
|
||||
// PixelMap
|
||||
console.log("Glide占位图输出=PixelMap")
|
||||
console.log("ImageKnife占位图输出=PixelMap")
|
||||
if (this.previousData.isSvg()) {
|
||||
console.log("Glide占位图输出=PixelMap 上一个是SVG")
|
||||
console.log("ImageKnife占位图输出=PixelMap 上一个是SVG")
|
||||
this.normalPixelMap = true;
|
||||
this.normalResource = true;
|
||||
|
||||
let pixelMapPack1 = new PixelMapPack();
|
||||
pixelMapPack1.pixelMap = new PixelMap();
|
||||
|
||||
this.glidePixelMapPack = pixelMapPack1;
|
||||
this.imageKnifePixelMapPack = pixelMapPack1;
|
||||
|
||||
setTimeout(() => {
|
||||
let pixelMapPack2 = new PixelMapPack();
|
||||
pixelMapPack2.pixelMap = data.glideValue as PixelMap;
|
||||
this.glidePixelMapPack = pixelMapPack2;
|
||||
pixelMapPack2.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.imageKnifePixelMapPack = pixelMapPack2;
|
||||
}, 100)
|
||||
} else {
|
||||
this.normalPixelMap = true;
|
||||
this.normalResource = true;
|
||||
|
||||
let pixelMapPack3 = new PixelMapPack();
|
||||
pixelMapPack3.pixelMap = data.glideValue as PixelMap;
|
||||
pixelMapPack3.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
|
||||
this.glidePixelMapPack = pixelMapPack3;
|
||||
this.imageKnifePixelMapPack = pixelMapPack3;
|
||||
}
|
||||
}
|
||||
else if (data.isString()) {
|
||||
// String
|
||||
console.log("glidevalue=" + JSON.stringify(data));
|
||||
console.log("Glide占位图输出=String")
|
||||
console.log("imageKnifevalue=" + JSON.stringify(data));
|
||||
console.log("ImageKnife占位图输出=String")
|
||||
if (this.previousData.isSvg()) {
|
||||
|
||||
console.log("data.glideValue=" + JSON.stringify(data.glideValue))
|
||||
console.log("Glide占位图输出=String 拥有上一个图片类型 上一个是SVG")
|
||||
console.log("data.imageKnifeValue=" + JSON.stringify(data.imageKnifeValue))
|
||||
console.log("ImageKnife占位图输出=String 拥有上一个图片类型 上一个是SVG")
|
||||
this.normalPixelMap = false;
|
||||
this.normalResource = false;
|
||||
let firstIndex = (data.glideValue as string).indexOf(diskGlide.getSvgAndGifFolder());
|
||||
let firstIndex = (data.imageKnifeValue as string).indexOf(DiskImageKnife.getSvgAndGifFolder());
|
||||
console.log("firstIndex=" + firstIndex);
|
||||
let suffix = (data.glideValue as string).substring(firstIndex, (data.glideValue as string).length)
|
||||
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
|
||||
console.log("suffix =" + suffix);
|
||||
let glideNeedStr = 'internal://app/' + suffix;
|
||||
this.glideString = glideNeedStr;
|
||||
let imageKnifeNeedStr = 'internal://app/' + suffix;
|
||||
this.imageKnifeString = imageKnifeNeedStr;
|
||||
} else {
|
||||
console.log("data.glideValue=" + JSON.stringify(data.glideValue))
|
||||
console.log("Glide占位图输出=String 拥有上一个图片类型 上一个不是SVG")
|
||||
console.log("data.imageKnifeValue=" + JSON.stringify(data.imageKnifeValue))
|
||||
console.log("ImageKnife占位图输出=String 拥有上一个图片类型 上一个不是SVG")
|
||||
|
||||
this.normalPixelMap = false;
|
||||
this.normalResource = false;
|
||||
let firstIndex = (data.glideValue as string).indexOf(diskGlide.getSvgAndGifFolder());
|
||||
let firstIndex = (data.imageKnifeValue as string).indexOf(DiskImageKnife.getSvgAndGifFolder());
|
||||
console.log("firstIndex=" + firstIndex);
|
||||
let suffix = (data.glideValue as string).substring(firstIndex, (data.glideValue as string).length)
|
||||
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
|
||||
console.log("suffix =" + suffix);
|
||||
let glideNeedStr = 'internal://app/' + suffix;
|
||||
this.glideString = glideNeedStr;
|
||||
let imageKnifeNeedStr = 'internal://app/' + suffix;
|
||||
this.imageKnifeString = imageKnifeNeedStr;
|
||||
}
|
||||
} else if (data.isResource()) {
|
||||
console.log("Glide占位图输出=Resource")
|
||||
console.log("ImageKnife占位图输出=Resource")
|
||||
if (this.previousData.isSvg()) {
|
||||
console.log("Glide占位图输出=Resource 上一个是SVG")
|
||||
console.log("ImageKnife占位图输出=Resource 上一个是SVG")
|
||||
this.normalPixelMap = false;
|
||||
this.normalResource = true;
|
||||
this.glideResource = data.glideValue as Resource;
|
||||
this.imageKnifeResource = data.imageKnifeValue as Resource;
|
||||
} else {
|
||||
this.normalPixelMap = false;
|
||||
this.normalResource = true;
|
||||
this.glideResource = data.glideValue as Resource;
|
||||
this.imageKnifeResource = data.imageKnifeValue as Resource;
|
||||
}
|
||||
} else {
|
||||
console.log("Glide占位图输出=数据错误")
|
||||
console.log("ImageKnife占位图输出=数据错误")
|
||||
}
|
||||
|
||||
} else {
|
||||
this.nowData = data;
|
||||
if (data.isPixelMap()) {
|
||||
// PixelMap
|
||||
console.log("Glide占位图输出=PixelMap")
|
||||
console.log("ImageKnife占位图输出=PixelMap")
|
||||
this.normalPixelMap = true;
|
||||
this.normalResource = true;
|
||||
|
||||
let pixelMapPack4 = new PixelMapPack();
|
||||
pixelMapPack4.pixelMap = data.glideValue as PixelMap;
|
||||
pixelMapPack4.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
|
||||
this.glidePixelMapPack = pixelMapPack4;
|
||||
this.imageKnifePixelMapPack = pixelMapPack4;
|
||||
}
|
||||
else if (data.isString()) {
|
||||
// String
|
||||
console.log("data.glideValue=" + JSON.stringify(data.glideValue))
|
||||
console.log("Glide占位图输出=String 没有上一个图片类型")
|
||||
console.log("data.imageKnifeValue=" + JSON.stringify(data.imageKnifeValue))
|
||||
console.log("ImageKnife占位图输出=String 没有上一个图片类型")
|
||||
this.normalPixelMap = false;
|
||||
this.normalResource = false;
|
||||
let firstIndex = (data.glideValue as string).indexOf(diskGlide.getSvgAndGifFolder());
|
||||
let firstIndex = (data.imageKnifeValue as string).indexOf(DiskImageKnife.getSvgAndGifFolder());
|
||||
console.log("firstIndex=" + firstIndex);
|
||||
let suffix = (data.glideValue as string).substring(firstIndex, (data.glideValue as string).length)
|
||||
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
|
||||
console.log("suffix =" + suffix);
|
||||
let glideNeedStr = 'internal://app/' + suffix;
|
||||
this.glideString = glideNeedStr;
|
||||
let imageKnifeNeedStr = 'internal://app/' + suffix;
|
||||
this.imageKnifeString = imageKnifeNeedStr;
|
||||
} else if (data.isResource()) {
|
||||
console.log("Glide占位图输出=Resource")
|
||||
console.log("ImageKnife占位图输出=Resource")
|
||||
this.normalPixelMap = false;
|
||||
this.normalResource = true;
|
||||
this.glideResource = data.glideValue as Resource;
|
||||
this.imageKnifeResource = data.imageKnifeValue as Resource;
|
||||
} else {
|
||||
console.log("Glide占位图输出=数据错误")
|
||||
console.log("ImageKnife占位图输出=数据错误")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -322,4 +318,4 @@ struct StorageTestDiskLruCache {
|
|||
|
||||
}
|
||||
}
|
||||
var diskGlide = globalThis.exports.default.data.glide
|
||||
var DiskImageKnife = globalThis.exports.default.data.imageKnife
|
|
@ -13,7 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import featureAbility from '@ohos.ability.featureAbility';
|
||||
import {LruCache} from '../cache/LruCache.ets'
|
||||
import {LruCache} from '@ohos/imageknife'
|
||||
|
||||
function getRandomInt(min, max) {
|
||||
min = Math.ceil(min);
|
||||
|
|
|
@ -12,12 +12,13 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {RequestOption} from "../glide/RequestOption.ets"
|
||||
import {AllCacheInfo,IAllCacheInfoCallback} from "../glide/interface/iallcacheinfocallback.ets"
|
||||
import {GlideImage} from "../glide/GlideImage.ets"
|
||||
import {PixelMapPack} from "../glide/PixelMapPack.ets"
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {RequestOption} from '@ohos/imageknife'
|
||||
import {AllCacheInfo,IAllCacheInfoCallback} from '@ohos/imageknife'
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {TransformType} from '@ohos/imageknife'
|
||||
import {PixelMapPack} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -26,48 +27,54 @@ struct TestAllCacheInfoPage {
|
|||
@State networkPixelMap: PixelMapPack = new PixelMapPack();
|
||||
allCacheInfoCallback1 =(allCacheInfo)=>{
|
||||
let info = allCacheInfo as AllCacheInfo;
|
||||
console.log("AllCacheInfoCallback glideimage1 memory ="+JSON.stringify(info.memoryCacheInfo))
|
||||
console.log("AllCacheInfoCallback glideimage1 resource ="+JSON.stringify(info.resourceCacheInfo))
|
||||
console.log("AllCacheInfoCallback glideimage1 data ="+JSON.stringify(info.dataCacheInfo))
|
||||
console.log("AllCacheInfoCallback imageknifecomponent1 memory ="+JSON.stringify(info.memoryCacheInfo))
|
||||
console.log("AllCacheInfoCallback imageknifecomponent1 resource ="+JSON.stringify(info.resourceCacheInfo))
|
||||
console.log("AllCacheInfoCallback imageknifecomponent1 data ="+JSON.stringify(info.dataCacheInfo))
|
||||
this.cacheinfo3 = "memory="+JSON.stringify(info.memoryCacheInfo)+
|
||||
"\n resource ="+JSON.stringify(info.resourceCacheInfo)+
|
||||
"\n data ="+JSON.stringify(info.dataCacheInfo)
|
||||
}
|
||||
allCacheInfoCallback2 =(allCacheInfo)=>{
|
||||
let info = allCacheInfo as AllCacheInfo;
|
||||
console.log("AllCacheInfoCallback glideimage2 memory ="+JSON.stringify(info.memoryCacheInfo))
|
||||
console.log("AllCacheInfoCallback glideimage2 resource ="+JSON.stringify(info.resourceCacheInfo))
|
||||
console.log("AllCacheInfoCallback glideimage2 data ="+JSON.stringify(info.dataCacheInfo))
|
||||
console.log("AllCacheInfoCallback imageknifecomponent2 memory ="+JSON.stringify(info.memoryCacheInfo))
|
||||
console.log("AllCacheInfoCallback imageknifecomponent2 resource ="+JSON.stringify(info.resourceCacheInfo))
|
||||
console.log("AllCacheInfoCallback imageknifecomponent2 data ="+JSON.stringify(info.dataCacheInfo))
|
||||
this.cacheinfo4 = "memory="+JSON.stringify(info.memoryCacheInfo)+
|
||||
"\n resource ="+JSON.stringify(info.resourceCacheInfo)+
|
||||
"\n data ="+JSON.stringify(info.dataCacheInfo)
|
||||
}
|
||||
@State glideOption1: GlideOption =
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
margin:{top:15},
|
||||
transformtions: [new RotateImageTransformation(180)],
|
||||
transform: {
|
||||
transformType:TransformType.RotateImageTransformation,
|
||||
rotateImage:180
|
||||
},
|
||||
allCacheInfoCallback:this.allCacheInfoCallback1
|
||||
};
|
||||
@State glideOption2: GlideOption =
|
||||
@State imageKnifeOption2: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83ericA1Mv66TwicuYOtbDMBcUhv1aa9RJBeAn9uURfcZD0AUGrJebAn1g2AjN0vb2E1XTET7fTuLBNmA/132",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
margin:{top:15},
|
||||
transformtions: [new RotateImageTransformation(180)],
|
||||
transform: {
|
||||
transformType:TransformType.RotateImageTransformation,
|
||||
rotateImage:180
|
||||
},
|
||||
allCacheInfoCallback:this.allCacheInfoCallback2
|
||||
};
|
||||
glideImageAngle:number = 90;
|
||||
imageKnifeComponentAngle:number = 90;
|
||||
|
||||
@State cacheinfo1:string = "观察本地资源获取缓存信息输出"
|
||||
@State cacheinfo2:string = "观察网络资源获取缓存信息输出"
|
||||
@State cacheinfo3:string = "观察GlideImage本地缓存输出"
|
||||
@State cacheinfo4:string = "观察GlideImage网络缓存输出"
|
||||
@State cacheinfo3:string = "观察ImageKnifeComponent本地缓存输出"
|
||||
@State cacheinfo4:string = "观察ImageKnifeComponent网络缓存输出"
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
|
@ -100,43 +107,49 @@ struct TestAllCacheInfoPage {
|
|||
.backgroundColor(Color.Green)
|
||||
.margin({ top: 15 })
|
||||
|
||||
Button("GlideImage加载本地资源获取缓存信息").width(300).height(25)
|
||||
Button("ImageKnifeComponent加载本地资源获取缓存信息").width(300).height(25)
|
||||
.onClick(() => {
|
||||
this.glideImageAngle = this.glideImageAngle + 45;
|
||||
this.glideOption1 =
|
||||
this.imageKnifeComponentAngle = this.imageKnifeComponentAngle + 45;
|
||||
this.imageKnifeOption1 =
|
||||
{
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
margin: { top: 15 },
|
||||
transformtions: [new RotateImageTransformation(this.glideImageAngle)],
|
||||
transform: {
|
||||
transformType:TransformType.RotateImageTransformation,
|
||||
rotateImage:this.imageKnifeComponentAngle
|
||||
},
|
||||
allCacheInfoCallback:this.allCacheInfoCallback1
|
||||
};
|
||||
}).margin({ top: 15 })
|
||||
Scroll() {
|
||||
Text(this.cacheinfo3).fontSize(15)
|
||||
}.width(300).height(200)
|
||||
GlideImage({ glideOption: $glideOption1 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
|
||||
Button("GlideImage加载网络资源获取缓存信息").width(300).height(25)
|
||||
Button("ImageKnifeComponent加载网络资源获取缓存信息").width(300).height(25)
|
||||
.onClick(() => {
|
||||
this.glideImageAngle = this.glideImageAngle + 45;
|
||||
this.glideOption2 =
|
||||
this.imageKnifeComponentAngle = this.imageKnifeComponentAngle + 45;
|
||||
this.imageKnifeOption2 =
|
||||
{
|
||||
loadSrc: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83ericA1Mv66TwicuYOtbDMBcUhv1aa9RJBeAn9uURfcZD0AUGrJebAn1g2AjN0vb2E1XTET7fTuLBNmA/132",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
margin: { top: 15 },
|
||||
transformtions: [new RotateImageTransformation(this.glideImageAngle)],
|
||||
transform: {
|
||||
transformType:TransformType.RotateImageTransformation,
|
||||
rotateImage:this.imageKnifeComponentAngle
|
||||
},
|
||||
allCacheInfoCallback:this.allCacheInfoCallback2
|
||||
};
|
||||
})
|
||||
Scroll() {
|
||||
Text(this.cacheinfo4).fontSize(15)
|
||||
}.width(300).height(200)
|
||||
GlideImage({ glideOption: $glideOption2 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption2 })
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -149,12 +162,12 @@ struct TestAllCacheInfoPage {
|
|||
}
|
||||
|
||||
private testAllCacheInfoNative() {
|
||||
let glideOption = new RequestOption();
|
||||
glideOption.load($r('app.media.pngSample'))
|
||||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load($r('app.media.pngSample'))
|
||||
.setImageViewSize({width:300,height:300})
|
||||
.addListener((err, data) => {
|
||||
let pack = new PixelMapPack();
|
||||
pack.pixelMap = data.glideValue as PixelMap;;
|
||||
pack.pixelMap = data.imageKnifeValue as PixelMap;;
|
||||
this.nativePixelMap = pack;
|
||||
return false;
|
||||
}).addAllCacheInfoCallback((allCacheInfo)=>{
|
||||
|
@ -166,17 +179,17 @@ struct TestAllCacheInfoPage {
|
|||
"\n resource ="+JSON.stringify(info.resourceCacheInfo)+
|
||||
"\n data ="+JSON.stringify(info.dataCacheInfo)
|
||||
})
|
||||
Glide.call(glideOption);
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
private testAllCacheInfoNetwork() {
|
||||
let glideOption2 = new RequestOption();
|
||||
glideOption2.load("https://hbimg.huabanimg.com/0ef60041445edcfd6b38d20e19024b2cd9281dcc3525a4-Vy8fYO_fw658/format/webp")
|
||||
let imageKnifeOption2 = new RequestOption();
|
||||
imageKnifeOption2.load("https://hbimg.huabanimg.com/0ef60041445edcfd6b38d20e19024b2cd9281dcc3525a4-Vy8fYO_fw658/format/webp")
|
||||
.addListener((err, data) => {
|
||||
let pack = new PixelMapPack();
|
||||
pack.pixelMap = data.glideValue as PixelMap;
|
||||
pack.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.networkPixelMap = pack;
|
||||
console.log("glide2 图片2 赋值!")
|
||||
console.log("imageknife2 图片2 赋值!")
|
||||
return false;
|
||||
}).addAllCacheInfoCallback((allCacheInfo)=>{
|
||||
let info = allCacheInfo as AllCacheInfo;
|
||||
|
@ -189,9 +202,9 @@ struct TestAllCacheInfoPage {
|
|||
})
|
||||
.setImageViewSize({width:300,height:300})
|
||||
.rotateImage(180)
|
||||
Glide.call(glideOption2);
|
||||
ImageKnife.call(imageKnifeOption2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
|
@ -12,62 +12,78 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from "../glide/GlideImage.ets"
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
import {TransformType} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct TestAllTypeGlideImagePage {
|
||||
@State glideOption1: GlideOption =
|
||||
struct TestAllTypeImageKnifeComponentPage {
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.Tomato'),
|
||||
errorholderSrc: $r('app.media.picture1'),
|
||||
transformtions: [new RotateImageTransformation(180)]
|
||||
transform: {
|
||||
transformType:TransformType.RotateImageTransformation,
|
||||
rotateImage:180
|
||||
}
|
||||
};
|
||||
@State glideOption2: GlideOption =
|
||||
@State imageKnifeOption2: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.Tomato'),
|
||||
errorholderSrc: $r('app.media.picture1'),
|
||||
transformtions: [new RotateImageTransformation(180)]
|
||||
transform: {
|
||||
transformType:TransformType.RotateImageTransformation,
|
||||
rotateImage:180
|
||||
}
|
||||
};
|
||||
@State glideOption3: GlideOption =
|
||||
@State imageKnifeOption3: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.webpSample'),
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.Tomato'),
|
||||
errorholderSrc: $r('app.media.picture1'),
|
||||
transformtions: [new RotateImageTransformation(180)]
|
||||
transform: {
|
||||
transformType:TransformType.RotateImageTransformation,
|
||||
rotateImage:180
|
||||
}
|
||||
};
|
||||
@State glideOption4: GlideOption =
|
||||
@State imageKnifeOption4: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.svgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.Tomato'),
|
||||
errorholderSrc: $r('app.media.picture1'),
|
||||
transformtions: [new RotateImageTransformation(180)]
|
||||
transform: {
|
||||
transformType:TransformType.RotateImageTransformation,
|
||||
rotateImage:180
|
||||
}
|
||||
};
|
||||
@State glideOption5: GlideOption =
|
||||
@State imageKnifeOption5: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.bmpSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.Tomato'),
|
||||
errorholderSrc: $r('app.media.picture1'),
|
||||
transformtions: [new RotateImageTransformation(180)]
|
||||
transform: {
|
||||
transformType:TransformType.RotateImageTransformation,
|
||||
rotateImage:180
|
||||
}
|
||||
};
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
GlideImage({ glideOption: $glideOption1 })
|
||||
GlideImage({ glideOption: $glideOption2 })
|
||||
GlideImage({ glideOption: $glideOption3 })
|
||||
GlideImage({ glideOption: $glideOption4 })
|
||||
GlideImage({ glideOption: $glideOption5 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption2 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption3 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption4 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption5 })
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
|
@ -80,4 +96,4 @@ struct TestAllTypeGlideImagePage {
|
|||
}
|
||||
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
|
@ -12,9 +12,9 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from "../glide/GlideImage.ets"
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -28,7 +28,7 @@ struct TestAllTypeNativeImagePage {
|
|||
Image($r('app.media.pngSample'))
|
||||
.width(300)
|
||||
.height(300)
|
||||
Image($r('app.media.webpSample'))
|
||||
Image($r('app.media.jpgSample'))
|
||||
.width(300)
|
||||
.height(300)
|
||||
Image($r('app.media.svgSample'))
|
||||
|
@ -49,4 +49,4 @@ struct TestAllTypeNativeImagePage {
|
|||
}
|
||||
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
|
@ -12,14 +12,14 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from '../glide/GlideImage.ets'
|
||||
import {GlideOption} from '../glide/GlideOption.ets'
|
||||
import {RotateImageTransformation} from '../glide/transform/RotateImageTransformation.ets'
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct TestGifDontAnimatePage {
|
||||
@State glideOption1: GlideOption =
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -35,7 +35,7 @@ struct TestGifDontAnimatePage {
|
|||
Flex({direction:FlexDirection.Row}){
|
||||
Button('本地资源gif')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.gifSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -46,7 +46,7 @@ struct TestGifDontAnimatePage {
|
|||
}).margin({left:15}).backgroundColor(Color.Grey)
|
||||
Button('本地资源gif静态')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.gifSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -61,7 +61,7 @@ struct TestGifDontAnimatePage {
|
|||
Flex({direction:FlexDirection.Row}){
|
||||
Button('网络资源gif')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: 'https://pic.ibaotu.com/gif/18/17/16/51u888piCtqj.gif!fwpaa70/fw/700',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -71,7 +71,7 @@ struct TestGifDontAnimatePage {
|
|||
}).margin({left:15}).backgroundColor(Color.Grey)
|
||||
Button('网络资源gif静态')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: 'https://pic.ibaotu.com/gif/18/17/16/51u888piCtqj.gif!fwpaa70/fw/700',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -82,7 +82,7 @@ struct TestGifDontAnimatePage {
|
|||
}).margin({left:15}).backgroundColor(Color.Grey)
|
||||
}
|
||||
.margin({top:15})
|
||||
GlideImage({ glideOption: $glideOption1 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -96,4 +96,4 @@ struct TestGifDontAnimatePage {
|
|||
}
|
||||
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
|
@ -12,14 +12,14 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from '../glide/GlideImage.ets'
|
||||
import {GlideOption} from '../glide/GlideOption.ets'
|
||||
import {RotateImageTransformation} from '../glide/transform/RotateImageTransformation.ets'
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct TestGlideOptionChangedPage {
|
||||
@State glideOption1: GlideOption =
|
||||
struct TestImageKnifeOptionChangedPage {
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -35,7 +35,7 @@ struct TestGlideOptionChangedPage {
|
|||
Flex({direction:FlexDirection.Row}){
|
||||
Button('本地资源jpg')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -46,7 +46,7 @@ struct TestGlideOptionChangedPage {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button('本地资源png')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -57,7 +57,7 @@ struct TestGlideOptionChangedPage {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button('本地资源bmp')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.bmpSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -68,8 +68,8 @@ struct TestGlideOptionChangedPage {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button('本地资源webp')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
loadSrc: $r('app.media.webpSample'),
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
|
@ -79,7 +79,7 @@ struct TestGlideOptionChangedPage {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button('本地资源svg')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.svgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -90,7 +90,7 @@ struct TestGlideOptionChangedPage {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button('本地资源gif')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.gifSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -104,7 +104,7 @@ struct TestGlideOptionChangedPage {
|
|||
Flex({direction:FlexDirection.Row}){
|
||||
Button('网络资源jpg')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: 'https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -114,7 +114,7 @@ struct TestGlideOptionChangedPage {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button('网络资源png')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: 'https://img-blog.csdnimg.cn/20191215043500229.png',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -124,7 +124,7 @@ struct TestGlideOptionChangedPage {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button('网络资源bmp')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: 'https://img-blog.csdn.net/20140514114029140',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -134,7 +134,7 @@ struct TestGlideOptionChangedPage {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button('网络资源webp')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: 'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -144,7 +144,7 @@ struct TestGlideOptionChangedPage {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button('网络资源svg')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: 'http://design-svc.fat.lunz.cn/StaticFiles/BP9999999772/BV9999999422/SA9999998420/30df266a-485e-411e-b178-b9fb1d8e0748.svg',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -154,7 +154,7 @@ struct TestGlideOptionChangedPage {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button('网络资源gif')
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: 'https://pic.ibaotu.com/gif/18/17/16/51u888piCtqj.gif!fwpaa70/fw/700',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -167,7 +167,7 @@ struct TestGlideOptionChangedPage {
|
|||
|
||||
Text('下面为展示图片区域').margin({top:5})
|
||||
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){
|
||||
GlideImage({ glideOption: $glideOption1 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
}.width(400).height(400).margin({top:10}).backgroundColor(Color.Pink)
|
||||
|
||||
|
||||
|
@ -183,4 +183,3 @@ struct TestGlideOptionChangedPage {
|
|||
}
|
||||
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
|
@ -12,14 +12,14 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from "../glide/GlideImage.ets"
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct TestGlideOptionChangedPage2 {
|
||||
@State glideOption1: GlideOption =
|
||||
struct TestImageKnifeOptionChangedPage2 {
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -36,7 +36,7 @@ struct TestGlideOptionChangedPage2 {
|
|||
Flex({direction:FlexDirection.Row}){
|
||||
Button("网络资源jpg")
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -47,7 +47,7 @@ struct TestGlideOptionChangedPage2 {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button("网络资源png")
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: "https://img-blog.csdnimg.cn/20191215043500229.png",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -58,7 +58,7 @@ struct TestGlideOptionChangedPage2 {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button("网络资源bmp")
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: "https://img-blog.csdn.net/20140514114029140",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -69,7 +69,7 @@ struct TestGlideOptionChangedPage2 {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button("网络资源webp")
|
||||
.onClick(()=>{
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: "https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -83,7 +83,7 @@ struct TestGlideOptionChangedPage2 {
|
|||
|
||||
Text("下面为展示图片区域").margin({top:5})
|
||||
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){
|
||||
GlideImage({ glideOption: $glideOption1 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
}.width(400).height(400).margin({top:10}).backgroundColor(Color.Pink)
|
||||
|
||||
|
||||
|
@ -99,4 +99,4 @@ struct TestGlideOptionChangedPage2 {
|
|||
}
|
||||
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import util from '@ohos.util';
|
||||
import {RequestOption} from "../glide/RequestOption.ets"
|
||||
//import {Glide} from '../glide/Glide'
|
||||
import{ALL} from "../cache/diskstrategy/enum/ALL"
|
||||
import{NONE} from "../cache/diskstrategy/enum/NONE"
|
||||
import {AsyncCallback} from "../glide/interface/asynccallback.ets"
|
||||
import {AsyncSuccess} from "../glide/interface/AsyncSuccess.ets"
|
||||
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct TestMemoryCachePage {
|
||||
@State tomatoPixelMap: PixelMap = new PixelMap();
|
||||
@State tomatoPixelMap2: PixelMap = new PixelMap();
|
||||
@State iceCreamPixelMap: PixelMap = new PixelMap();
|
||||
|
||||
build() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Image(this.tomatoPixelMap)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.objectFit(ImageFit.Contain)
|
||||
.backgroundColor(Color.Green)
|
||||
.onClick(() => {
|
||||
})
|
||||
Image(this.iceCreamPixelMap)
|
||||
.backgroundColor(Color.Grey)
|
||||
.objectFit(ImageFit.Contain)
|
||||
.width(200)
|
||||
.height(200)
|
||||
Image(this.tomatoPixelMap2)
|
||||
.objectFit(ImageFit.Contain)
|
||||
.backgroundColor(Color.Orange)
|
||||
.width(200)
|
||||
.height(200)
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
console.log("aboutToAppear()")
|
||||
this.testAllResourceLoading();
|
||||
}
|
||||
|
||||
private testAllResourceLoading() {
|
||||
|
||||
let glideOption = new RequestOption();
|
||||
glideOption.load($r('app.media.Tomato'))
|
||||
.addListener((err, data) => {
|
||||
console.log("glide1 图片1 赋值!")
|
||||
this.tomatoPixelMap = data.glideValue as PixelMap;
|
||||
return false;
|
||||
})
|
||||
|
||||
Glide.call(glideOption);
|
||||
|
||||
|
||||
let glideOption2 = new RequestOption();
|
||||
glideOption2.load($r('app.media.IceCream'))
|
||||
.addListener((err, data) => {
|
||||
this.iceCreamPixelMap = data.glideValue as PixelMap;
|
||||
console.log("glide2 图片2 赋值!")
|
||||
return false;
|
||||
})
|
||||
|
||||
Glide.call(glideOption2);
|
||||
|
||||
|
||||
let glideOption3 = new RequestOption();
|
||||
glideOption3.load($r('app.media.Tomato'))
|
||||
.addListener((err, data) => {
|
||||
this.tomatoPixelMap2 = data.glideValue as PixelMap;
|
||||
console.log("glide3 图片1 赋值!")
|
||||
return false;
|
||||
})
|
||||
|
||||
Glide.call(glideOption3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
|
@ -12,15 +12,15 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from '../glide/GlideImage.ets'
|
||||
import {GlideOption} from '../glide/GlideOption.ets'
|
||||
import {RequestOption} from '../glide/RequestOption.ets'
|
||||
import {RotateImageTransformation} from '../glide/transform/RotateImageTransformation.ets'
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RequestOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct TestPreloadPage {
|
||||
@State glideOption1: GlideOption =
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -28,7 +28,7 @@ struct TestPreloadPage {
|
|||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
margin: { left: 15, top: 15, right: 15, bottom: 15 }
|
||||
};
|
||||
@State glideOption2: GlideOption =
|
||||
@State imageKnifeOption2: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -36,7 +36,7 @@ struct TestPreloadPage {
|
|||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
margin: { left: 15, top: 15, right: 15, bottom: 15 }
|
||||
};
|
||||
@State glideOption3: GlideOption =
|
||||
@State imageKnifeOption3: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -45,7 +45,7 @@ struct TestPreloadPage {
|
|||
margin: { left: 15, top: 15, right: 15, bottom: 15 }
|
||||
};
|
||||
|
||||
@State glideOption4: GlideOption =
|
||||
@State imageKnifeOption4: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -53,7 +53,7 @@ struct TestPreloadPage {
|
|||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
margin: { left: 15, top: 15, right: 15, bottom: 15 }
|
||||
};
|
||||
@State glideOption5: GlideOption =
|
||||
@State imageKnifeOption5: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
|
@ -61,9 +61,9 @@ struct TestPreloadPage {
|
|||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
margin: { left: 15, top: 15, right: 15, bottom: 15 }
|
||||
};
|
||||
@State glideOption6: GlideOption =
|
||||
@State imageKnifeOption6: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.webpSample'),
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
|
@ -84,11 +84,11 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载本地资源gif 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源gif成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载本地资源gif成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -96,7 +96,7 @@ struct TestPreloadPage {
|
|||
|
||||
Button('本地资源gif')
|
||||
.onClick(() => {
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.gifSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -118,18 +118,18 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载本地资源gif静态 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源gif静态成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载本地资源gif静态成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
||||
Button('本地资源gif静态')
|
||||
.onClick(() => {
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.gifSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -155,18 +155,18 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源gif 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源gif成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载网络资源gif成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
||||
Button('网络资源gif')
|
||||
.onClick(() => {
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: 'https://pic.ibaotu.com/gif/18/17/16/51u888piCtqj.gif!fwpaa70/fw/700',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -187,18 +187,18 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源gif静态 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源gif静态成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载网络资源gif静态成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
||||
Button('网络资源gif静态')
|
||||
.onClick(() => {
|
||||
this.glideOption1 = {
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: 'https://pic.ibaotu.com/gif/18/17/16/51u888piCtqj.gif!fwpaa70/fw/700',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -212,7 +212,7 @@ struct TestPreloadPage {
|
|||
}
|
||||
.margin({ top: 15 })
|
||||
|
||||
GlideImage({ glideOption: $glideOption1 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
|
||||
}
|
||||
|
||||
|
@ -227,11 +227,11 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载本地资源svg 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源svg成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载本地资源svg成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -239,7 +239,7 @@ struct TestPreloadPage {
|
|||
|
||||
Button('本地资源svg')
|
||||
.onClick(() => {
|
||||
this.glideOption2 = {
|
||||
this.imageKnifeOption2 = {
|
||||
loadSrc: $r('app.media.svgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -266,18 +266,18 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源gif 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源gif成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载网络资源gif成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
||||
Button('网络资源svg')
|
||||
.onClick(() => {
|
||||
this.glideOption2 = {
|
||||
this.imageKnifeOption2 = {
|
||||
loadSrc: 'http://design-svc.fat.lunz.cn/StaticFiles/BP9999999772/BV9999999422/SA9999998420/4dc8463e-8ac6-4eb4-862c-783bf486a242.svg',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -292,7 +292,7 @@ struct TestPreloadPage {
|
|||
}
|
||||
.margin({ top: 15 })
|
||||
|
||||
GlideImage({ glideOption: $glideOption2 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption2 })
|
||||
|
||||
}
|
||||
|
||||
|
@ -301,17 +301,17 @@ struct TestPreloadPage {
|
|||
Button('预加载本地资源webp')
|
||||
.onClick(() => {
|
||||
let request = new RequestOption();
|
||||
request.load($r('app.media.webpSample'))
|
||||
request.load($r('app.media.jpgSample'))
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载本地资源webp 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源webp成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载本地资源webp成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -319,8 +319,8 @@ struct TestPreloadPage {
|
|||
|
||||
Button('本地资源webp')
|
||||
.onClick(() => {
|
||||
this.glideOption3 = {
|
||||
loadSrc: $r('app.media.webpSample'),
|
||||
this.imageKnifeOption3 = {
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
|
@ -346,18 +346,18 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源webp 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源webp成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载网络资源webp成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
||||
Button('网络资源webp')
|
||||
.onClick(() => {
|
||||
this.glideOption3 = {
|
||||
this.imageKnifeOption3 = {
|
||||
loadSrc: 'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -370,7 +370,7 @@ struct TestPreloadPage {
|
|||
}
|
||||
.margin({ top: 15 })
|
||||
|
||||
GlideImage({ glideOption: $glideOption3 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption3 })
|
||||
|
||||
}
|
||||
|
||||
|
@ -385,11 +385,11 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载本地资源bmp 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源bmp成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载本地资源bmp成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -397,7 +397,7 @@ struct TestPreloadPage {
|
|||
|
||||
Button('本地资源bmp')
|
||||
.onClick(() => {
|
||||
this.glideOption4 = {
|
||||
this.imageKnifeOption4 = {
|
||||
loadSrc: $r('app.media.bmpSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -424,18 +424,18 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源bmp 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源bmp成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载网络资源bmp成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
||||
Button('网络资源bmp')
|
||||
.onClick(() => {
|
||||
this.glideOption4 = {
|
||||
this.imageKnifeOption4 = {
|
||||
loadSrc: 'https://img-blog.csdn.net/20140514114029140',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -448,7 +448,7 @@ struct TestPreloadPage {
|
|||
}
|
||||
.margin({ top: 15 })
|
||||
|
||||
GlideImage({ glideOption: $glideOption4 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption4 })
|
||||
|
||||
}
|
||||
|
||||
|
@ -463,11 +463,11 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载本地资源png 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源png成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载本地资源png成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -475,7 +475,7 @@ struct TestPreloadPage {
|
|||
|
||||
Button('本地资源png')
|
||||
.onClick(() => {
|
||||
this.glideOption5 = {
|
||||
this.imageKnifeOption5 = {
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -502,18 +502,18 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源bmp 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源bmp成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载网络资源bmp成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
||||
Button('网络资源png')
|
||||
.onClick(() => {
|
||||
this.glideOption5 = {
|
||||
this.imageKnifeOption5 = {
|
||||
loadSrc: 'https://img-blog.csdnimg.cn/20191215043500229.png',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -526,7 +526,7 @@ struct TestPreloadPage {
|
|||
}
|
||||
.margin({ top: 15 })
|
||||
|
||||
GlideImage({ glideOption: $glideOption5 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption5 })
|
||||
|
||||
}
|
||||
|
||||
|
@ -541,11 +541,11 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载本地资源jpg 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源jpg成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载本地资源jpg成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -553,7 +553,7 @@ struct TestPreloadPage {
|
|||
|
||||
Button('本地资源jpg')
|
||||
.onClick(() => {
|
||||
this.glideOption6 = {
|
||||
this.imageKnifeOption6 = {
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -580,18 +580,18 @@ struct TestPreloadPage {
|
|||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源jpg 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源jpg成功! glidedata=' + JSON.stringify(data))
|
||||
console.log('预加载网络资源jpg成功! imageknifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
Glide.preload(request);
|
||||
ImageKnife.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
||||
Button('网络资源jpg')
|
||||
.onClick(() => {
|
||||
this.glideOption6 = {
|
||||
this.imageKnifeOption6 = {
|
||||
loadSrc: 'https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB',
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
|
@ -604,7 +604,7 @@ struct TestPreloadPage {
|
|||
}
|
||||
.margin({ top: 15 })
|
||||
|
||||
GlideImage({ glideOption: $glideOption6 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption6 })
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -619,4 +619,4 @@ struct TestPreloadPage {
|
|||
}
|
||||
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
|
@ -12,24 +12,24 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {RequestOption} from "../glide/RequestOption.ets"
|
||||
import{NONE} from "../cache/diskstrategy/enum/NONE"
|
||||
import {Base64} from "../cache/Base64.ets"
|
||||
import {FileTypeUtil} from "../glide/utils/FileTypeUtil.ets"
|
||||
import {GlideData} from "../glide/GlideData.ets"
|
||||
import {RequestOption} from '@ohos/imageknife'
|
||||
import{NONE} from '@ohos/imageknife'
|
||||
import {Base64} from '@ohos/imageknife'
|
||||
import {FileTypeUtil} from '@ohos/imageknife'
|
||||
import {ImageKnifeData} from '@ohos/imageknife'
|
||||
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
@Entry
|
||||
@Component
|
||||
struct TestResourceManagerPage {
|
||||
|
||||
@State glideData: GlideData = new GlideData();
|
||||
@State imageKnifeData: ImageKnifeData = new ImageKnifeData();
|
||||
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Text(this.glideData.glideType)
|
||||
Text(this.imageKnifeData.imageKnifeType)
|
||||
.fontSize(20)
|
||||
.backgroundColor(Color.Pink)
|
||||
.width(300)
|
||||
|
@ -50,10 +50,10 @@ struct TestResourceManagerPage {
|
|||
let fileTypeUtil = new FileTypeUtil();
|
||||
let typeValue = fileTypeUtil.getFileType(arrayBuffer);
|
||||
console.log("typeValue data=" + typeValue)
|
||||
let newGlideData = new GlideData();
|
||||
newGlideData.glideType = typeValue
|
||||
let newImageKnifeData = new ImageKnifeData();
|
||||
newImageKnifeData.imageKnifeType = typeValue
|
||||
|
||||
this.glideData = newGlideData;
|
||||
this.imageKnifeData = newImageKnifeData;
|
||||
})
|
||||
|
||||
})
|
||||
|
@ -69,9 +69,9 @@ struct TestResourceManagerPage {
|
|||
let fileTypeUtil = new FileTypeUtil();
|
||||
let typeValue = fileTypeUtil.getFileType(this.typedArrayToBuffer(data));
|
||||
console.log("typeValue data=" + typeValue)
|
||||
let newGlideData = new GlideData();
|
||||
newGlideData.glideType = typeValue
|
||||
this.glideData = newGlideData;
|
||||
let newImageKnifeData = new ImageKnifeData();
|
||||
newImageKnifeData.imageKnifeType = typeValue
|
||||
this.imageKnifeData = newImageKnifeData;
|
||||
})
|
||||
|
||||
})
|
||||
|
@ -92,4 +92,4 @@ struct TestResourceManagerPage {
|
|||
|
||||
}
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
|
@ -12,30 +12,32 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {RequestOption} from "../glide/RequestOption.ets"
|
||||
import {CropCircleTransformation} from "../glide/transform/CropCircleTransformation.ets"
|
||||
import {RoundedCornersTransformation} from "../glide/transform/RoundedCornersTransformation.ets"
|
||||
import {CropCircleWithBorderTransformation} from "../glide/transform/CropCircleWithBorderTransformation.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {CropSquareTransformation} from "../glide/transform/CropSquareTransformation.ets"
|
||||
import {CropTransformation} from "../glide/transform/CropTransformation.ets"
|
||||
import {CropType} from "../glide/transform/CropTransformation"
|
||||
import {GrayscaleTransformation} from "../glide/transform/GrayscaleTransformation"
|
||||
import {BrightnessFilterTransformation} from "../glide/transform/BrightnessFilterTransformation"
|
||||
import {ContrastFilterTransformation} from "../glide/transform/ContrastFilterTransformation"
|
||||
import {InvertFilterTransformation} from "../glide/transform/InvertFilterTransformation"
|
||||
import {SepiaFilterTransformation} from "../glide/transform/SepiaFilterTransformation"
|
||||
import {SketchFilterTransformation} from "../glide/transform/SketchFilterTransformation"
|
||||
import {BlurTransformation} from "../glide/transform/BlurTransformation"
|
||||
import {PixelationFilterTransformation} from "../glide/transform/PixelationFilterTransformation"
|
||||
import {PixelMapPack} from "../glide/PixelMapPack.ets";
|
||||
import {RequestOption} from '@ohos/imageknife'
|
||||
import {CropCircleTransformation} from '@ohos/imageknife'
|
||||
import {RoundedCornersTransformation} from '@ohos/imageknife'
|
||||
import {CropCircleWithBorderTransformation} from '@ohos/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
import {CropSquareTransformation} from '@ohos/imageknife'
|
||||
import {CropTransformation} from '@ohos/imageknife'
|
||||
import {CropType} from '@ohos/imageknife'
|
||||
import {GrayscaleTransformation} from '@ohos/imageknife'
|
||||
import {BrightnessFilterTransformation} from '@ohos/imageknife'
|
||||
import {ContrastFilterTransformation} from '@ohos/imageknife'
|
||||
import {InvertFilterTransformation} from '@ohos/imageknife'
|
||||
import {SepiaFilterTransformation} from '@ohos/imageknife'
|
||||
import {SketchFilterTransformation} from '@ohos/imageknife'
|
||||
import {BlurTransformation} from '@ohos/imageknife'
|
||||
import {PixelationFilterTransformation} from '@ohos/imageknife'
|
||||
import {MaskTransformation} from '@ohos/imageknife'
|
||||
import {SwirlFilterTransformation} from '@ohos/imageknife'
|
||||
import {PixelMapPack} from '@ohos/imageknife'
|
||||
|
||||
/**
|
||||
* PixelMap transform 示例
|
||||
*/
|
||||
let mRotate: number = 0;
|
||||
//let mUrl = "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB"
|
||||
let mUrl = $r('app.media.transformBase');
|
||||
let mUrl = $r('app.media.check_big');
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -58,6 +60,8 @@ struct TransformPixelMapPage {
|
|||
@State mSketchPixelMap: PixelMapPack= new PixelMapPack();
|
||||
@State mBlurPixelMap: PixelMapPack= new PixelMapPack();
|
||||
@State mPixelPixelMap: PixelMapPack= new PixelMapPack();
|
||||
@State mSwirlPixelMap: PixelMapPack= new PixelMapPack();
|
||||
@State mMaskPixelMap: PixelMapPack= new PixelMapPack();
|
||||
|
||||
build() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
|
||||
|
@ -165,9 +169,8 @@ struct TransformPixelMapPage {
|
|||
this.circleTransformation();
|
||||
});
|
||||
Image(this.mCirclePixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -184,9 +187,8 @@ struct TransformPixelMapPage {
|
|||
this.circleBorderTransformation(5);
|
||||
});
|
||||
Image(this.mCircleBorderPixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -207,9 +209,8 @@ struct TransformPixelMapPage {
|
|||
this.transformRotate(mRotate);
|
||||
});
|
||||
Image(this.mRotatePixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -227,8 +228,8 @@ struct TransformPixelMapPage {
|
|||
});
|
||||
Image(this.mSquarePixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -242,7 +243,7 @@ struct TransformPixelMapPage {
|
|||
.height(35)
|
||||
.width(72)
|
||||
.onClick(() => {
|
||||
this.clipPixelMap(25,25, CropType.TOP);
|
||||
this.clipPixelMap(25, 25, CropType.TOP);
|
||||
});
|
||||
Button() {
|
||||
Text($r("app.string.trans_clip_center")).fontSize(13).fontColor(Color.White)
|
||||
|
@ -250,7 +251,7 @@ struct TransformPixelMapPage {
|
|||
.height(35)
|
||||
.width(72)
|
||||
.onClick(() => {
|
||||
this.clipPixelMap(25,25, CropType.CENTER);
|
||||
this.clipPixelMap(25, 25, CropType.CENTER);
|
||||
});
|
||||
Button() {
|
||||
Text($r("app.string.trans_clip_bottom")).fontSize(13).fontColor(Color.White)
|
||||
|
@ -258,7 +259,7 @@ struct TransformPixelMapPage {
|
|||
.height(35)
|
||||
.width(72)
|
||||
.onClick(() => {
|
||||
this.clipPixelMap(25,25, CropType.BOTTOM);
|
||||
this.clipPixelMap(25, 25, CropType.BOTTOM);
|
||||
});
|
||||
}.margin({ top: 10 })
|
||||
|
||||
|
@ -294,8 +295,8 @@ struct TransformPixelMapPage {
|
|||
});
|
||||
Image(this.mGrayscalePixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -312,8 +313,8 @@ struct TransformPixelMapPage {
|
|||
});
|
||||
Image(this.mBrightnessPixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -330,8 +331,8 @@ struct TransformPixelMapPage {
|
|||
});
|
||||
Image(this.mContrastPixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -348,8 +349,8 @@ struct TransformPixelMapPage {
|
|||
});
|
||||
Image(this.mInvertPixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -367,8 +368,8 @@ struct TransformPixelMapPage {
|
|||
});
|
||||
Image(this.mSepiaPixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -385,8 +386,8 @@ struct TransformPixelMapPage {
|
|||
});
|
||||
Image(this.mSketchPixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -404,8 +405,8 @@ struct TransformPixelMapPage {
|
|||
});
|
||||
Image(this.mBlurPixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -424,8 +425,46 @@ struct TransformPixelMapPage {
|
|||
});
|
||||
Image(this.mPixelPixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(100)
|
||||
.height(100)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
||||
Column() {
|
||||
Text("SwirlFilterTransformation").fontColor(Color.Gray).fontSize(16);
|
||||
Button() {
|
||||
Text("图片Swirl").fontSize(13).fontColor(Color.White)
|
||||
}
|
||||
.height(35)
|
||||
.width(120)
|
||||
.margin({ top: 10 })
|
||||
.onClick(() => {
|
||||
this.swirlHandlePixelMap();
|
||||
});
|
||||
Image(this.mSwirlPixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
||||
Column() {
|
||||
Text("MaskTransformation").fontColor(Color.Gray).fontSize(16);
|
||||
Button() {
|
||||
Text("图片mask").fontSize(13).fontColor(Color.White)
|
||||
}
|
||||
.height(35)
|
||||
.width(120)
|
||||
.margin({ top: 10 })
|
||||
.onClick(() => {
|
||||
this.maskHandlePixelMap($r('app.media.mask_starfish'));
|
||||
});
|
||||
Image(this.mMaskPixelMap.pixelMap)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
|
||||
}.margin({ top: 10 });
|
||||
|
@ -440,390 +479,401 @@ struct TransformPixelMapPage {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* centerCrop
|
||||
*/
|
||||
centerCrop() {
|
||||
var glideOption = new RequestOption();
|
||||
glideOption.load($r('app.media.photo5'))
|
||||
// glideOption.load(mUrl)
|
||||
var imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load($r('app.media.photo5'))
|
||||
// imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
this.mCropPixelMap = result;
|
||||
setTimeout(() => {
|
||||
let result2 = new PixelMapPack();
|
||||
result2.pixelMap = data.glideValue as PixelMap;
|
||||
result2.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mCropPixelMap = result2;
|
||||
},100)
|
||||
}, 100)
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.skipMemoryCache(true)
|
||||
.centerCrop();
|
||||
Glide.call(glideOption);
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* centerInside
|
||||
*/
|
||||
centerInside() {
|
||||
var glideOption = new RequestOption();
|
||||
glideOption.load($r('app.media.Back'))
|
||||
//glideOption.load(mUrl)
|
||||
var imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load($r('app.media.Back'))
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
this.mCropPixelMap = result;
|
||||
setTimeout(() => {
|
||||
let result2 = new PixelMapPack();
|
||||
result2.pixelMap = data.glideValue as PixelMap;
|
||||
result2.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mCropPixelMap = result2;
|
||||
},100)
|
||||
}, 100)
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.skipMemoryCache(true)
|
||||
.centerInside();
|
||||
Glide.call(glideOption);
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* centerInside
|
||||
*/
|
||||
fitCenter() {
|
||||
var glideOption = new RequestOption()
|
||||
glideOption.load($r('app.media.Back'))
|
||||
//glideOption.load(mUrl)
|
||||
var imageKnifeOption = new RequestOption()
|
||||
imageKnifeOption.load($r('app.media.Back'))
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
this.mCropPixelMap = result;
|
||||
setTimeout(() => {
|
||||
let result2 = new PixelMapPack();
|
||||
result2.pixelMap = data.glideValue as PixelMap;
|
||||
result2.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mCropPixelMap = result2;
|
||||
},100)
|
||||
}, 100)
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.skipMemoryCache(true)
|
||||
.fitCenter();
|
||||
Glide.call(glideOption);
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* 圆角设置
|
||||
*/
|
||||
roundedCornersTransformation(top_left: number,
|
||||
bottom_left: number, top_right: number, bottom_right: number) {
|
||||
bottom_left: number, top_right: number, bottom_right: number) {
|
||||
|
||||
var glideOption = new RequestOption();
|
||||
|
||||
//glideOption.load($r('app.media.photo5'))
|
||||
glideOption.load(mUrl)
|
||||
var imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
this.mRoundPixelMap = result;
|
||||
setTimeout(() => {
|
||||
let result2 = new PixelMapPack();
|
||||
result2.pixelMap = data.glideValue as PixelMap;
|
||||
result2.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mRoundPixelMap = result2;
|
||||
},100)
|
||||
}, 100)
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(new RoundedCornersTransformation({ top_left: top_left, top_right: top_right
|
||||
, bottom_left: bottom_left, bottom_right: bottom_right }))
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.roundedCorners({ top_left: top_left, top_right: top_right, bottom_left: bottom_left, bottom_right: bottom_right })
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 裁剪圆
|
||||
*/
|
||||
circleTransformation() {
|
||||
let glideOption = new RequestOption();
|
||||
// glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mCirclePixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(new CropCircleTransformation())
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.cropCircle()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 圆环裁剪
|
||||
*/
|
||||
circleBorderTransformation(border: number) {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var circleTransformation = new CropCircleWithBorderTransformation(border,
|
||||
{ r_color: 255, g_color: 204, b_color: 204 });
|
||||
//glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mCircleBorderPixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(circleTransformation)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.cropCircleWithBorder(border,
|
||||
{ r_color: 255, g_color: 204, b_color: 204 })
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 旋转
|
||||
*/
|
||||
transformRotate(angled: number) {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new RotateImageTransformation(angled);
|
||||
//glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mRotatePixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(transformation)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.rotateImage(angled)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 正方形裁剪
|
||||
*/
|
||||
transformSquare() {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new CropSquareTransformation();
|
||||
// glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mSquarePixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(transformation)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.cropSquare()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 区域裁剪
|
||||
*/
|
||||
clipPixelMap(width: number, height: number, cropType: CropType) {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new CropTransformation(width, height, cropType);
|
||||
// glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
if (cropType == CropType.TOP) {
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mClipTopPixelMap = result;
|
||||
} else if (cropType == CropType.CENTER) {
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mClipCenterPixelMap = result;
|
||||
} else if (cropType == CropType.BOTTOM) {
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mClipBottomPixelMap = result;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: width, height: height })
|
||||
.skipMemoryCache(true)
|
||||
.transform(transformation)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.crop(width, height, cropType)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 灰度
|
||||
*/
|
||||
grayscalePixelMap() {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new GrayscaleTransformation();
|
||||
// glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mGrayscalePixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(transformation)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.grayscale()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*亮度b
|
||||
*/
|
||||
brightnessPixelMap(brightness: number) {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new BrightnessFilterTransformation(brightness);
|
||||
// glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mBrightnessPixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(transformation)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.brightnessFilter(brightness)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*对比度
|
||||
*/
|
||||
contrastPixelMap(contrast: number) {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new ContrastFilterTransformation(contrast);
|
||||
// glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mContrastPixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(transformation)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.contrastFilter(contrast)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*反转处理
|
||||
*/
|
||||
invertPixelMap() {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new InvertFilterTransformation();
|
||||
// glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mInvertPixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(transformation)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.invertFilter()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*照片老旧出来(黑褐色)
|
||||
*/
|
||||
sepiaPixelMap() {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new SepiaFilterTransformation();
|
||||
// glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mSepiaPixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(transformation)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.sepiaFilter()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*素描
|
||||
*/
|
||||
sketchPixelMap() {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new SketchFilterTransformation();
|
||||
// glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mSketchPixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(transformation)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.sketchFilter()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*模糊
|
||||
*/
|
||||
blurHandlePixelMap(radius: number) {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new BlurTransformation(radius);
|
||||
// glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mBlurPixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(transformation)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
.blur(radius)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
/**
|
||||
/**
|
||||
*马赛克
|
||||
*/
|
||||
pixelHandlePixelMap(pixel: number) {
|
||||
let glideOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new PixelationFilterTransformation(pixel);
|
||||
// glideOption.load($r('app.media.photo6'))
|
||||
glideOption.load(mUrl)
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap=data.glideValue as PixelMap;
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mPixelPixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.transform(transformation)
|
||||
.pixelationFilter(pixel)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*扭曲
|
||||
*/
|
||||
swirlHandlePixelMap() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new SwirlFilterTransformation(80);
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mSwirlPixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.swirlFilter(80)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
Glide.call(glideOption);
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
/**
|
||||
*遮罩
|
||||
*/
|
||||
maskHandlePixelMap(maskResource: Resource) {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new MaskTransformation(maskResource);
|
||||
// imageKnifeOption.load($r('app.media.photo6'))
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = new PixelMapPack();
|
||||
result.pixelMap = data.imageKnifeValue as PixelMap;
|
||||
this.mMaskPixelMap = result;
|
||||
return false;
|
||||
})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.mask(maskResource)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
|
@ -12,63 +12,77 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {GlideImage} from "../glide/GlideImage.ets"
|
||||
import {GlideOption} from "../glide/GlideOption.ets"
|
||||
import {RotateImageTransformation} from "../glide/transform/RotateImageTransformation.ets"
|
||||
import {RoundedCornersTransformation} from "../glide/transform/RoundedCornersTransformation.ets"
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
import {RoundedCornersTransformation} from '@ohos/imageknife'
|
||||
import {TransformType} from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State glideOption1: GlideOption =
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83ericA1Mv66TwicuYOtbDMBcUhv1aa9RJBeAn9uURfcZD0AUGrJebAn1g2AjN0vb2E1XTET7fTuLBNmA/132",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.Tomato'),
|
||||
errorholderSrc: $r('app.media.picture1'),
|
||||
transformtions: [new RotateImageTransformation(180)]
|
||||
transform: {
|
||||
transformType:TransformType.RotateImageTransformation,
|
||||
rotateImage:180
|
||||
}
|
||||
};
|
||||
@State glideOption2: GlideOption =
|
||||
@State imageKnifeOption2: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83ericA1Mv66TwicuYOtbDMBcUhv1aa9RJBeAn9uURfcZD0AUGrJebAn1g2AjN0vb2E1XTET7fTuLBNmA/132",
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.Tomato'),
|
||||
errorholderSrc: $r('app.media.picture1'),
|
||||
transformtions: [new RoundedCornersTransformation({
|
||||
top_left: 30,
|
||||
top_right: 30,
|
||||
bottom_left: 30,
|
||||
bottom_right: 30
|
||||
})]
|
||||
transform: {
|
||||
transformType:TransformType.RoundedCornersTransformation,
|
||||
roundedCorners:{
|
||||
top_left: 30,
|
||||
top_right: 30,
|
||||
bottom_left: 30,
|
||||
bottom_right: 30
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@State glideOption3: GlideOption =
|
||||
@State imageKnifeOption3: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.Tomato'),
|
||||
errorholderSrc: $r('app.media.picture1'),
|
||||
transformtions: [new RotateImageTransformation(180)]
|
||||
transform: {
|
||||
transformType:TransformType.RotateImageTransformation,
|
||||
rotateImage:180
|
||||
}
|
||||
};
|
||||
@State glideOption4: GlideOption =
|
||||
@State imageKnifeOption4: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
size: { width: 300, height: 300 },
|
||||
placeholderSrc: $r('app.media.Tomato'),
|
||||
errorholderSrc: $r('app.media.picture1'),
|
||||
transformtions: [new RoundedCornersTransformation({
|
||||
top_left: 130,
|
||||
top_right: 130,
|
||||
bottom_left: 130,
|
||||
bottom_right: 130
|
||||
})]
|
||||
transform: {
|
||||
transformType:TransformType.RoundedCornersTransformation,
|
||||
roundedCorners:{
|
||||
top_left: 130,
|
||||
top_right: 130,
|
||||
bottom_left: 130,
|
||||
bottom_right: 130
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
build() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
GlideImage({ glideOption: $glideOption1 })
|
||||
GlideImage({ glideOption: $glideOption2 })
|
||||
GlideImage({ glideOption: $glideOption3 })
|
||||
GlideImage({ glideOption: $glideOption4 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption1 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption2 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption3 })
|
||||
ImageKnifeComponent({ imageKnifeOption: $imageKnifeOption4 })
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
|
@ -80,4 +94,3 @@ struct Index {
|
|||
}
|
||||
|
||||
|
||||
var Glide = globalThis.exports.default.data.glide
|
|
@ -13,25 +13,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import arkWorker from '@ohos.worker';
|
||||
import {handler} from '@ohos/imageknife/src/main/ets/components/imageknife/pngj/PngWork'
|
||||
|
||||
arkWorker.parentPort.onmessage = handler
|
||||
|
||||
arkWorker.parentPort.onmessage = function (e) {
|
||||
var data = e.data;
|
||||
switch (data.type) {
|
||||
case 'normal':
|
||||
arkWorker.parentPort.postMessage(data);
|
||||
break;
|
||||
case 'error':
|
||||
throw new Error('123');
|
||||
break;
|
||||
case 'buffer':
|
||||
let uint8Array = new Uint8Array(data.data);
|
||||
arkWorker.parentPort.postMessage(data, [data.data]);
|
||||
|
||||
break;
|
||||
default:
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "GlideJS_OHOS",
|
||||
"value": "GlideJS_OHOS"
|
||||
"name": "ImageKnife_OHOS",
|
||||
"value": "ImageKnife_OHOS"
|
||||
},
|
||||
{
|
||||
"name": "mainability_description",
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 6.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 7.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 40 KiB |
Binary file not shown.
Before Width: | Height: | Size: 40 KiB |
|
@ -0,0 +1,68 @@
|
|||
{
|
||||
"app": {
|
||||
"bundleName": "com.example.imageknifegiteepro",
|
||||
"vendor": "example",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.example.entry_test",
|
||||
"name": ".entry_test",
|
||||
"mainAbility": ".TestAbility",
|
||||
"srcPath": "",
|
||||
"deviceType": [
|
||||
"phone",
|
||||
"tablet"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry_test",
|
||||
"moduleType": "feature",
|
||||
"installationFree": false
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
],
|
||||
"orientation": "unspecified",
|
||||
"visible": true,
|
||||
"srcPath": "TestAbility",
|
||||
"name": ".TestAbility",
|
||||
"srcLanguage": "ets",
|
||||
"icon": "$media:icon",
|
||||
"description": "$string:description_TestAbility",
|
||||
"formsEnabled": false,
|
||||
"label": "$string:entry_TestAbility",
|
||||
"type": "page",
|
||||
"launchType": "standard"
|
||||
}
|
||||
],
|
||||
"js": [
|
||||
{
|
||||
"mode": {
|
||||
"syntax": "ets",
|
||||
"type": "pageAbility"
|
||||
},
|
||||
"pages": [
|
||||
"pages/index"
|
||||
],
|
||||
"name": ".TestAbility",
|
||||
"window": {
|
||||
"designWidth": 720,
|
||||
"autoDesignWidth": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
export default {
|
||||
onCreate() {
|
||||
console.info('Application onCreate')
|
||||
},
|
||||
onShow() {
|
||||
console.info('Application onShow')
|
||||
},
|
||||
onDestroy() {
|
||||
console.info('Application onDestroy')
|
||||
},
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"strings": {
|
||||
"hello": "Hello",
|
||||
"world": "World"
|
||||
},
|
||||
"Files": {
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"strings": {
|
||||
"hello": "您好",
|
||||
"world": "世界"
|
||||
},
|
||||
"Files": {
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
import {Core, ExpectExtend, InstrumentLog} from "deccjsunit/index"
|
||||
import testsuite from "../../../test/List.test.ets"
|
||||
import app from '@system.app'
|
||||
import featureAbility from "@ohos.ability.featureAbility"
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct MyComponent {
|
||||
aboutToAppear() {
|
||||
console.info("start run testcase!!!!")
|
||||
featureAbility.getWant()
|
||||
.then((Want) => {
|
||||
const core = Core.getInstance()
|
||||
const instrumentLog = new InstrumentLog({
|
||||
'id': 'report', 'unity': 'true'
|
||||
})
|
||||
const expectExtend = new ExpectExtend({
|
||||
'id': 'extend'
|
||||
})
|
||||
core.addService('expect', expectExtend)
|
||||
core.addService('report', instrumentLog)
|
||||
core.init()
|
||||
core.subscribeEvent('spec', instrumentLog)
|
||||
core.subscribeEvent('suite', instrumentLog)
|
||||
core.subscribeEvent('task', instrumentLog)
|
||||
const configService = core.getDefaultService('config')
|
||||
configService.setConfig(Want.parameters)
|
||||
testsuite()
|
||||
core.execute()
|
||||
console.info('Operation successful. Data: ' + JSON.stringify(Want));
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Operation failed. Cause: ' + JSON.stringify(error));
|
||||
})
|
||||
}
|
||||
|
||||
build() {
|
||||
Flex({
|
||||
direction: FlexDirection.Column,
|
||||
alignItems: ItemAlign.Center,
|
||||
justifyContent: FlexAlign.Center
|
||||
}) {
|
||||
Text('Hello World')
|
||||
.fontSize(50)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
|
||||
import { Hypium } from 'hypium/index'
|
||||
import testsuite from '../test/List.test'
|
||||
|
||||
export default {
|
||||
onCreate() {
|
||||
console.info('Application onCreate')
|
||||
var abilityDelegator: any
|
||||
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
|
||||
var abilityDelegatorArguments: any
|
||||
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
|
||||
console.info('start run testcase!!!')
|
||||
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
|
||||
},
|
||||
onDestroy() {
|
||||
console.info('Application onDestroy')
|
||||
},
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
import router from '@system.router';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
aboutToAppear() {
|
||||
console.info('TestAbility index aboutToAppear')
|
||||
}
|
||||
|
||||
@State message: string = 'Hello World'
|
||||
build() {
|
||||
Row() {
|
||||
Column() {
|
||||
Text(this.message)
|
||||
.fontSize(50)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
Button() {
|
||||
Text('next page')
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
}.type(ButtonType.Capsule)
|
||||
.margin({
|
||||
top: 20
|
||||
})
|
||||
.backgroundColor('#0D9FFB')
|
||||
.width('35%')
|
||||
.height('5%')
|
||||
.onClick(()=>{
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.height('100%')
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
import TestRunner from '@ohos.application.testRunner'
|
||||
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
|
||||
|
||||
var abilityDelegator = undefined
|
||||
var abilityDelegatorArguments = undefined
|
||||
|
||||
function translateParamsToString(parameters) {
|
||||
const keySet = new Set([
|
||||
'-s class', '-s notClass', '-s suite', '-s itName',
|
||||
'-s level', '-s testType', '-s size', '-s timeout',
|
||||
'-s package'
|
||||
])
|
||||
let targetParams = '';
|
||||
for (const key in parameters) {
|
||||
if (keySet.has(key)) {
|
||||
targetParams += ' ' + key + ' ' + parameters[key]
|
||||
}
|
||||
}
|
||||
return targetParams.trim()
|
||||
}
|
||||
|
||||
async function onAbilityCreateCallback() {
|
||||
console.log('onAbilityCreateCallback');
|
||||
}
|
||||
|
||||
async function addAbilityMonitorCallback(err: any) {
|
||||
console.info('addAbilityMonitorCallback : ' + JSON.stringify(err))
|
||||
}
|
||||
|
||||
export default class OpenHarmonyTestRunner implements TestRunner {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
onPrepare() {
|
||||
console.info('OpenHarmonyTestRunner OnPrepare')
|
||||
}
|
||||
|
||||
onRun() {
|
||||
console.log('OpenHarmonyTestRunner onRun run')
|
||||
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
|
||||
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
|
||||
|
||||
let lMonitor = {
|
||||
abilityName: testAbilityName,
|
||||
onAbilityCreate: onAbilityCreateCallback,
|
||||
};
|
||||
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
|
||||
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
|
||||
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
|
||||
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
|
||||
console.info('cmd : '+cmd)
|
||||
abilityDelegator.executeShellCommand(cmd,
|
||||
(err: any, d: any) => {
|
||||
console.info('executeShellCommand : err : ' + JSON.stringify(err));
|
||||
console.info('executeShellCommand : data : ' + d.stdResult);
|
||||
console.info('executeShellCommand : data : ' + d.exitCode);
|
||||
})
|
||||
console.info('OpenHarmonyTestRunner onRun call abilityDelegator.getAppContext')
|
||||
var context = abilityDelegator.getAppContext()
|
||||
console.info('getAppContext : ' + JSON.stringify(context))
|
||||
console.info('OpenHarmonyTestRunner onRun end')
|
||||
}
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index'
|
||||
|
||||
export default function abilityTest() {
|
||||
describe('ActsAbilityTest', function () {
|
||||
it('assertContain',0, function () {
|
||||
console.info("it begin")
|
||||
let a = 'abc'
|
||||
let b = 'b'
|
||||
expect(a).assertContain(b)
|
||||
expect(a).assertEqual(a)
|
||||
})
|
||||
})
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index"
|
||||
import app from '@system.app'
|
||||
|
||||
export default function exampleJsunit() {
|
||||
describe('appInfoTest', function () {
|
||||
it('app_info_test_001', 0, function () {
|
||||
var info = app.getInfo()
|
||||
expect("1.0")
|
||||
.assertEqual('1.0')
|
||||
expect(info.versionCode)
|
||||
.assertEqual('3')
|
||||
})
|
||||
})
|
||||
}
|
|
@ -1,229 +0,0 @@
|
|||
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index"
|
||||
import featureability from '@ohos.ability.featureAbility'
|
||||
import {Glide} from '../../../main/ets/default/glide/Glide.ets'
|
||||
import {GlideData} from '../../../main/ets/default/glide/GlideData.ets'
|
||||
import {LruCache} from '../../../main/ets/default/cache/LruCache'
|
||||
import {DiskLruCache} from '../../../main/ets/default/cache/DiskLruCache'
|
||||
import {AsyncCallback} from "../../../main/ets/default/glide/interface/asynccallback.ets"
|
||||
import dataStorage from '@ohos.data.storage';
|
||||
import {FileUtils} from '../../../main/ets/default/cache/FileUtils'
|
||||
import {TransformUtils} from '../../../main/ets/default/glide/transform/TransformUtils.ets'
|
||||
import resmgr from '@ohos.resourceManager'
|
||||
import {ColorUtils} from "../../../main/ets/default/glide/utils/ColorUtils.ets";
|
||||
import {DataCallBack} from "../../../main/ets/default/glide/interface/DataCallBack.ets";
|
||||
|
||||
|
||||
export default function glidejsRootJsunit() {
|
||||
|
||||
describe('GlideJSTest', function () {
|
||||
let filePath = '/data/data/com.huawei.mydemoall/files'
|
||||
let cachePath = '/data/data/com.huawei.mydemoall/cache'
|
||||
|
||||
let GlideSingleton;
|
||||
beforeAll(function () {
|
||||
GlideSingleton = Glide.with();
|
||||
});
|
||||
|
||||
it('glidejs_test_001', 0, function () {
|
||||
expect(GlideSingleton != null && GlideSingleton != undefined).assertEqual(true)
|
||||
})
|
||||
|
||||
// 替换MemoryCache
|
||||
it('glidejs_glide_test_001', 0, function () {
|
||||
expect(GlideSingleton.getMemoryCache()
|
||||
.maxsize).assertEqual(100)
|
||||
GlideSingleton.setMemoryCache(new LruCache<string, any>(200))
|
||||
expect(GlideSingleton.getMemoryCache()
|
||||
.maxsize).assertEqual(200)
|
||||
})
|
||||
|
||||
// 替换DiskLruCache
|
||||
it('glidejs_glide_test_002', 0, function () {
|
||||
expect(GlideSingleton.getDiskMemoryCache()
|
||||
.maxsize).assertEqual(30 * 1024 * 1024)
|
||||
GlideSingleton.setDiskMemoryCache(new DiskLruCache(40 * 1024 * 1024))
|
||||
expect(GlideSingleton.getDiskMemoryCache()
|
||||
.maxsize).assertEqual(40 * 1024 * 1024)
|
||||
})
|
||||
|
||||
// 替换svgAndGifFolder
|
||||
it('glidejs_glide_test_003', 0, function () {
|
||||
expect(GlideSingleton.getSvgAndGifFolder()).assertEqual("svgAndGifFolder")
|
||||
GlideSingleton.setSvgAndGifFolder("renameFolder")
|
||||
expect(GlideSingleton.getSvgAndGifFolder()).assertEqual("renameFolder")
|
||||
})
|
||||
|
||||
// 替换defaultListener
|
||||
it('glidejs_glide_test_004', 0, function () {
|
||||
expect(GlideSingleton.getDefaultListener() != null && GlideSingleton.getDefaultListener() != undefined)
|
||||
.assertEqual(false)
|
||||
GlideSingleton.setDefaultListener((err, glideData: GlideData) => {
|
||||
// watch callback
|
||||
})
|
||||
expect(GlideSingleton.getDefaultListener() != null && GlideSingleton.getDefaultListener() != undefined)
|
||||
.assertEqual(true)
|
||||
})
|
||||
|
||||
// fileutils createFile
|
||||
it('glidejs_file_utils_test_001', 0, function () {
|
||||
let fd = FileUtils.getInstance().createFile(this.filePath + "temp1.txt")
|
||||
expect(fd > 0).assertEqual(true)
|
||||
})
|
||||
|
||||
// fileutils clearFile
|
||||
it('glidejs_file_utils_test_002', 0, function () {
|
||||
let fd = FileUtils.getInstance().clearFile(this.filePath + "temp1.txt")
|
||||
expect(fd > 0).assertEqual(true)
|
||||
})
|
||||
|
||||
// fileutils exist
|
||||
it('glidejs_file_utils_test_003', 0, function () {
|
||||
let result = FileUtils.getInstance().exist(this.filePath + "temp1.txt")
|
||||
expect(result).assertEqual(true)
|
||||
})
|
||||
|
||||
// fileutils getFileSize
|
||||
it('glidejs_file_utils_test_004', 0, function () {
|
||||
let size = FileUtils.getInstance().getFileSize(this.filePath + "temp1.txt")
|
||||
expect(size).assertEqual(0)
|
||||
})
|
||||
|
||||
// fileutils existFolder
|
||||
it('glidejs_file_utils_test_005', 0, function () {
|
||||
let result = FileUtils.getInstance().existFolder(this.filePath)
|
||||
expect(result).assertEqual(true)
|
||||
})
|
||||
|
||||
// fileutils stringToUint8Array
|
||||
it('glidejs_file_utils_test_006', 0, function () {
|
||||
let result = FileUtils.getInstance().stringToUint8Array("A")
|
||||
expect(result[0]).assertEqual(65)
|
||||
})
|
||||
|
||||
// fileutils stringToUint8Array
|
||||
it('glidejs_file_utils_test_007', 0, function () {
|
||||
let uint8array = FileUtils.getInstance().stringToUint8Array("A")
|
||||
let result = FileUtils.getInstance().uint8ArrayToBuffer(uint8array)
|
||||
expect(result[0]).assertEqual(65)
|
||||
})
|
||||
|
||||
// LruCache get
|
||||
it('glidejs_lrucache_test_001', 0, function () {
|
||||
let lruCache = new LruCache<string, any>(5)
|
||||
lruCache.put("1", 1);
|
||||
lruCache.put("2", 2);
|
||||
lruCache.put("3", 3);
|
||||
lruCache.put("4", 4);
|
||||
lruCache.put("5", 5);
|
||||
expect(lruCache.get("1")).assertEqual(1)
|
||||
})
|
||||
|
||||
// LruCache resize maxsize trimToSize
|
||||
it('glidejs_lrucache_test_002', 0, function () {
|
||||
let lruCache = new LruCache<string, any>(5)
|
||||
lruCache.put("1", 1);
|
||||
lruCache.put("2", 2);
|
||||
lruCache.put("3", 3);
|
||||
lruCache.put("4", 4);
|
||||
lruCache.put("5", 5);
|
||||
lruCache.get("1")
|
||||
lruCache.resize(4)
|
||||
expect(lruCache.maxSize()).assertEqual(4)
|
||||
expect(lruCache.get("2") == undefined).assertEqual(true)
|
||||
})
|
||||
|
||||
// DiskLruCache putCacheData getCacheDataByKey
|
||||
it('glidejs_disklrucache_test_001', 0, function () {
|
||||
let diskLruCache = new DiskLruCache(40 * 1024 * 1024)
|
||||
let uint8Array = new Uint8Array([1,2,3,4])
|
||||
let arraybuffer = FileUtils.getInstance().uint8ArrayToBuffer(uint8Array);
|
||||
diskLruCache.putCacheData("1",arraybuffer,null)
|
||||
let getValue = diskLruCache.getCacheDataByKey("1")
|
||||
|
||||
let uint8GetValue = new Uint8Array(getValue);
|
||||
expect(uint8Array[0]).assertEqual(1)
|
||||
expect(uint8Array[1]).assertEqual(2)
|
||||
expect(uint8Array[2]).assertEqual(3)
|
||||
expect(uint8Array[3]).assertEqual(4)
|
||||
})
|
||||
|
||||
// DiskLruCache cleanCacheData
|
||||
it('glidejs_disklrucache_test_002', 0, function () {
|
||||
let diskLruCache = new DiskLruCache(40 * 1024 * 1024)
|
||||
let uint8Array = new Uint8Array([1,2,3,4])
|
||||
let arraybuffer = FileUtils.getInstance().uint8ArrayToBuffer(uint8Array);
|
||||
diskLruCache.putCacheData("1",arraybuffer,null)
|
||||
diskLruCache.cleanCacheData();
|
||||
let getValue = diskLruCache.getCacheDataByKey("1")
|
||||
expect(getValue==null).assertEqual(true)
|
||||
})
|
||||
|
||||
// DiskLruCache getCacheFileByKey
|
||||
it('glidejs_disklrucache_test_003', 0, function () {
|
||||
let diskLruCache = new DiskLruCache(40 * 1024 * 1024)
|
||||
let uint8Array = new Uint8Array([1,2,3,4])
|
||||
let arraybuffer = FileUtils.getInstance().uint8ArrayToBuffer(uint8Array);
|
||||
diskLruCache.putCacheData("1",arraybuffer,null)
|
||||
let path = diskLruCache.getCacheFileByKey("1");
|
||||
expect(path!=null).assertEqual(true)
|
||||
})
|
||||
|
||||
// DiskLruCache setMaxSize
|
||||
it('glidejs_disklrucache_test_004', 0, function () {
|
||||
let diskLruCache = new DiskLruCache(40 * 1024 * 1024)
|
||||
diskLruCache.setMaxSize(20 * 1024 * 1024)
|
||||
expect(diskLruCache.maxSize==(20 * 1024 * 1024)).assertEqual(true)
|
||||
})
|
||||
|
||||
|
||||
// DiskLruCache deleteCacheDataBykey
|
||||
it('glidejs_disklrucache_test_005', 0, function () {
|
||||
let diskLruCache = new DiskLruCache(40 * 1024 * 1024)
|
||||
let uint8Array = new Uint8Array([1,2,3,4])
|
||||
let arraybuffer = FileUtils.getInstance().uint8ArrayToBuffer(uint8Array);
|
||||
diskLruCache.putCacheData("1",arraybuffer,null)
|
||||
diskLruCache.deleteCacheDataBykey("1");
|
||||
let value = diskLruCache.getCacheDataByKey("1")
|
||||
expect(value == null).assertEqual(true)
|
||||
})
|
||||
|
||||
//pngj
|
||||
it('glidejs_pngj_test_001', 0, function () {
|
||||
let pngj = new Pngj();
|
||||
let uint8Array = new Uint8Array([1,2,3,4])
|
||||
let inputArray = FileUtils.getInstance().uint8ArrayToBuffer(uint8Array);
|
||||
pngj.writePng(inputArray,(buffer1)=>{
|
||||
let uint8array1 = new Uint8Array(buffer1);
|
||||
let pngj1length = uint8array1.byteLength;
|
||||
pngj.writePngWithString("hello",inputArray,(buffer2)=>{
|
||||
let uint8array2 = new Uint8Array(buffer2);
|
||||
let pngj2length = uint8array2.byteLength;
|
||||
expect(pngj2length > pngj1length).assertEqual(true)
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
it('glidejs_color_test_01', 0, function () {
|
||||
let call: DataCallBack<string> = {
|
||||
callback(data: string) {
|
||||
expect(data != null).assertEqual(true)
|
||||
}
|
||||
}
|
||||
ColorUtils.parseColor("test_color", call);
|
||||
})
|
||||
|
||||
it('glidejs_color_test_02', 0, function () {
|
||||
expect(ColorUtils.red(1325455) == ((1325455 >> 16) & 0xFF)).assertEqual(true);
|
||||
})
|
||||
it('glidejs_color_test_03', 0, function () {
|
||||
expect(ColorUtils.blue(1325455) == (1325455 & 0xFF)).assertEqual(true);
|
||||
})
|
||||
it('glidejs_color_test_04', 0, function () {
|
||||
expect(ColorUtils.green(1325455) == ((1325455 >> 8) & 0xFF)).assertEqual(true);
|
||||
})
|
||||
it('glidejs_color_test_05', 0, function () {
|
||||
expect(ColorUtils.rgb(25, 123, 150) == (0xff000000 | (25 << 16) | (123 << 8) | 150)).assertEqual(true);
|
||||
})
|
||||
})
|
||||
}
|
|
@ -1,5 +1,19 @@
|
|||
import exampleJsunit from "../test/ExampleJsunit.test.ets"
|
||||
import GlideJSTest from '../test/GlideJSTest.test.ets'
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
import abilityTest from './Ability.test'
|
||||
|
||||
export default function testsuite() {
|
||||
GlideJSTest()
|
||||
abilityTest()
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "GlideJSCache"
|
||||
"name": "description_TestAbility",
|
||||
"value": "eTS_Empty Ability"
|
||||
},
|
||||
{
|
||||
"name": "mainability_description",
|
||||
"value": "hap sample empty page"
|
||||
"name": "entry_TestAbility",
|
||||
"value": "entry_TestAbility"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. DevEco Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
# If the Chinese output is garbled, please configure the following parameter.
|
||||
# This function is enabled by default when the DevEco Studio builds the hap/app,if you need disable gradle parallel,you should set org.gradle.parallel false.
|
||||
# more information see https://docs.gradle.org/current/userguide/performance.html
|
||||
# org.gradle.parallel=false
|
||||
# org.gradle.jvmargs=-Dfile.encoding=GBK
|
Binary file not shown.
|
@ -1,5 +0,0 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-7.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
|
@ -1,183 +0,0 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# https://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.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
|
@ -1,103 +0,0 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle 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
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
|
@ -0,0 +1,2 @@
|
|||
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
||||
module.exports = require('@ohos/hvigor-ohos-plugin').legacyAppTasks
|
|
@ -0,0 +1,3 @@
|
|||
/node_modules
|
||||
/.preview
|
||||
/build
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"apiType": "faMode",
|
||||
"buildOption": {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
||||
module.exports = require('@ohos/hvigor-ohos-plugin').legacyHarTasks
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* cache
|
||||
*/
|
||||
|
||||
export * from './src/main/ets/components/cache/FileUtils'
|
||||
export * from './src/main/ets/components/cache/Md5'
|
||||
export * from './src/main/ets/components/cache/Base64'
|
||||
export * from './src/main/ets/components/cache/LruCache'
|
||||
export * from './src/main/ets/components/cache/DiskLruCache'
|
||||
export * from './src/main/ets/components/cache/diskstrategy/enum/ALL'
|
||||
export * from './src/main/ets/components/cache/diskstrategy/enum/AUTOMATIC'
|
||||
export * from './src/main/ets/components/cache/diskstrategy/enum/DATA'
|
||||
export * from './src/main/ets/components/cache/diskstrategy/enum/NONE'
|
||||
export * from './src/main/ets/components/cache/diskstrategy/enum/RESOURCE'
|
||||
|
||||
/**
|
||||
* compress
|
||||
*/
|
||||
export * from './src/main/ets/components/imageknife/compress/CompressBuilder'
|
||||
export * from './src/main/ets/components/imageknife/compress/listener/OnCompressListener'
|
||||
export * from './src/main/ets/components/imageknife/compress/listener/OnRenameListener'
|
||||
export * from './src/main/ets/components/imageknife/compress/listener/CompressDataListener'
|
||||
export * from './src/main/ets/components/imageknife/compress/listener/CompressionPredicate'
|
||||
export * from './src/main/ets/components/imageknife/compress/provider/CompressAdapter'
|
||||
export * from './src/main/ets/components/imageknife/compress/provider/CompressProvider'
|
||||
export * from './src/main/ets/components/imageknife/compress/provider/DataStringPathProvider'
|
||||
export * from './src/main/ets/components/imageknife/compress/provider/RecourseProvider'
|
||||
|
||||
/**
|
||||
* crop
|
||||
*/
|
||||
export * from './src/main/ets/components/imageknife/crop/Crop'
|
||||
export * from './src/main/ets/components/imageknife/crop/CropImage'
|
||||
export * from './src/main/ets/components/imageknife/crop/CropOptions'
|
||||
|
||||
/**
|
||||
* transform
|
||||
*/
|
||||
export * from './src/main/ets/components/imageknife/transform/BaseTransform'
|
||||
export * from './src/main/ets/components/imageknife/transform/BlurTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/BrightnessFilterTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/ContrastFilterTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/CropCircleTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/CropSquareTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/CropTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/GrayscaleTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/InvertFilterTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/PixelationFilterTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/RotateImageTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/RoundedCornersTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/SepiaFilterTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/SketchFilterTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/MaskTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/SwirlFilterTransformation'
|
||||
export * from './src/main/ets/components/imageknife/transform/TransformUtils'
|
||||
export * from './src/main/ets/components/imageknife/transform/TransformType'
|
||||
export * from './src/main/ets/components/imageknife/transform/pixelmap/CenterCrop'
|
||||
export * from './src/main/ets/components/imageknife/transform/pixelmap/CenterInside'
|
||||
export * from './src/main/ets/components/imageknife/transform/pixelmap/FitCenter'
|
||||
|
||||
/**
|
||||
* pngj
|
||||
*/
|
||||
export * from './src/main/ets/components/imageknife/pngj/Pngj'
|
||||
export {handler} from './src/main/ets/components/imageknife/pngj/PngWork'
|
||||
export * from './src/main/ets/components/imageknife/pngj/UPNG'
|
||||
|
||||
/**
|
||||
* ImageKnife
|
||||
*/
|
||||
export * from './src/main/ets/components/imageknife/ImageKnife'
|
||||
export * from './src/main/ets/components/imageknife/RequestOption'
|
||||
export * from './src/main/ets/components/imageknife/ImageKnifeComponent'
|
||||
export * from './src/main/ets/components/imageknife/ImageKnifeOption'
|
||||
export * from './src/main/ets/components/imageknife/ImageKnifeData'
|
||||
export * from './src/main/ets/components/imageknife/PixelMapPack'
|
||||
export * from './src/main/ets/components/imageknife/interface/IAllCacheInfoCallback'
|
||||
export * from './src/main/ets/components/imageknife/interface/IParseImage'
|
||||
export * from './src/main/ets/components/imageknife/networkmanage/IDataFetch'
|
||||
export * from './src/main/ets/components/imageknife/requestmanage/ICache'
|
||||
export * from './src/main/ets/components/imageknife/utils/FileTypeUtil'
|
||||
export * from './src/main/ets/components/imageknife/utils/ParseImageUtil'
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "@ohos/imageknife",
|
||||
"version": "1.0.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"pako": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "http://mirrors.tools.huawei.com/npm/pako/-/pako-1.0.11.tgz",
|
||||
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"types": "",
|
||||
"keywords": [
|
||||
"openharmony",
|
||||
"imageknife"
|
||||
],
|
||||
"author": "ohos_tpc",
|
||||
"description": "专门为OpenHarmony打造的一款图像加载缓存库,致力于更高效、更轻便、更简单",
|
||||
"ohos": {
|
||||
"org": "opensource"
|
||||
},
|
||||
"main": "index.ets",
|
||||
"repository": "https://gitee.com/openharmony-tpc/imageknife.git",
|
||||
"version": "1.0.1",
|
||||
"dependencies": {
|
||||
"pako": "^1.0.5"
|
||||
},
|
||||
"tags": [
|
||||
"openharmony",
|
||||
"imageknife"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {},
|
||||
"name": "@ohos/imageknife"
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"app": {
|
||||
"bundleName": "com.example.imageknifegiteepro",
|
||||
"vendor": "example",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.example.imageknife",
|
||||
"deviceType": [
|
||||
"phone",
|
||||
"tablet"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "imageknife",
|
||||
"moduleType": "har"
|
||||
},
|
||||
"uiSyntax": "ets"
|
||||
}
|
||||
}
|
|
@ -18,14 +18,14 @@ import {FileReader} from './FileReader'
|
|||
import {DiskCacheEntry} from './DiskCacheEntry'
|
||||
import fileio from '@ohos.fileio';
|
||||
import featureability from '@ohos.ability.featureAbility'
|
||||
import {Md5} from './Md5.ets'
|
||||
import {Md5} from './Md5'
|
||||
|
||||
export class DiskLruCache {
|
||||
|
||||
// 缓存数据集合
|
||||
cacheMap: CustomMap<string, DiskCacheEntry> = new CustomMap<string, DiskCacheEntry>()
|
||||
fileUtils: FileUtils = FileUtils.getInstance()
|
||||
diskCacheFolder: string = 'GlideDiskCache'
|
||||
diskCacheFolder: string = 'ImageKnifeDiskCache'
|
||||
|
||||
// 缓存文件路劲地址
|
||||
dirPath: string= ''
|
|
@ -16,35 +16,13 @@ import{DataSrc} from "../diskstrategy/DataSrc"
|
|||
import{EncodeStrategy} from "../diskstrategy/EncodeStrategy"
|
||||
|
||||
export interface DiskStrategy {
|
||||
/**
|
||||
* Returns true if this request should cache the original unmodified data.
|
||||
*
|
||||
* @param dataSource Indicates where the data was originally retrieved.
|
||||
* @return boolean
|
||||
*/
|
||||
|
||||
isDataCacheable(dataSource: DataSrc): boolean
|
||||
|
||||
/**
|
||||
* Returns true if this request should cache the final transformed resource.
|
||||
*
|
||||
* @param isFromAlternateCacheKey {@code true} if the resource we've decoded was loaded using an
|
||||
* alternative, rather than the primary, cache key.
|
||||
* @param dataSource Indicates where the data used to decode the resource was originally
|
||||
* retrieved.
|
||||
* @param encodeStrategy The {@link EncodeStrategy} the {@link
|
||||
* com.bumptech.glide.load.ResourceEncoder} will use to encode the resource.
|
||||
* @return boolean
|
||||
*/
|
||||
isResourceCacheable(isFromAlternateCacheKey: boolean, dataSource: DataSrc, encodeStrategy: EncodeStrategy): boolean;
|
||||
|
||||
/** Returns true if this request should attempt to decode cached resource data.
|
||||
* @return boolean
|
||||
*/
|
||||
decodeCachedResource(): boolean;
|
||||
|
||||
/** Returns true if this request should attempt to decode cached source data.
|
||||
* @return boolean
|
||||
*/
|
||||
decodeCachedData(): boolean;
|
||||
|
||||
getName(): string;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue