自定义下载改为仅支持主图和修改requestInSteam配置、新增ColorFilter属性
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
This commit is contained in:
parent
7ecc9faf9f
commit
a1f80ce93f
|
@ -1,5 +1,8 @@
|
|||
## 3.0.0-rc.10
|
||||
## 3.0.0
|
||||
- 修复图形变换的闪退问题
|
||||
- 自定义下载customGetImage改为仅主图支持
|
||||
- 修改网络请求requestInStream配置优先返回arraybuffer
|
||||
- 新增ColorFilter属性
|
||||
|
||||
## 3.0.0-rc.9
|
||||
- 修复Resource类型$r(变量无法)加载
|
||||
|
|
|
@ -277,6 +277,8 @@ ImageKnifeComponent({
|
|||
| signature | String | 自定义缓存关键字(可选) |
|
||||
| headerOption | Array<HeaderOptions> | 设置请求头(可选) |
|
||||
| transformation | PixelMapTransformation | 图片变换(可选) |
|
||||
| drawingColorFilter | ColorFilter | drawing.ColorFilter | 图片变换(可选) |
|
||||
| onComplete | (event:EventImage | undefined) => voi | 颜色滤镜效果(可选) |
|
||||
| onLoadListener | onLoadStart: () => void、onLoadSuccess: (data: string | PixelMap | undefined) => void、onLoadFailed: (err: string) => void| 监听图片加载成功与失败 |
|
||||
|
||||
### ImageKnife接口
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
import { ImageKnifeComponent,BlurTransformation } from '@ohos/libraryimageknife';
|
||||
import fs from '@ohos.file.fs';
|
||||
import image from '@ohos.multimedia.image';
|
||||
import { common2D, drawing } from '@kit.ArkGraphics2D';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -23,6 +24,8 @@ struct SingleImage {
|
|||
scroller: Scroller = new Scroller;
|
||||
localFile: string = getContext(this).filesDir + "/icon.png"
|
||||
@State pixelMap:PixelMap | undefined = undefined;
|
||||
@State DrawingColorFilter: ColorFilter | undefined = undefined
|
||||
private color: common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
|
||||
aboutToAppear(): void {
|
||||
// 拷贝本地文件
|
||||
let icon: Uint8Array = getContext(this).resourceManager.getMediaContentSync($r("app.media.startIcon"));
|
||||
|
@ -44,12 +47,15 @@ struct SingleImage {
|
|||
.fontWeight(FontWeight.Bold)
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: {
|
||||
loadSrc: $r(this.resource),
|
||||
loadSrc: $r("app.media.svgSample"),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
objectFit: ImageFit.Contain
|
||||
}
|
||||
}).width(100).height(100)
|
||||
.onClick(()=>{
|
||||
this.DrawingColorFilter = drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN);
|
||||
})
|
||||
Text("本地context files下文件")
|
||||
.fontSize(30)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"main": "index.ets",
|
||||
"repository": "https://gitee.com/openharmony-tpc/ImageKnife",
|
||||
"type": "module",
|
||||
"version": "3.0.0-rc.10",
|
||||
"version": "3.0.0",
|
||||
"dependencies": {
|
||||
"@ohos/gpu_transform": "^1.0.2"
|
||||
},
|
||||
|
|
|
@ -383,7 +383,7 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
|
|||
let fileKey = request.engineKey.generateFileKey(request.src, request.signature)
|
||||
|
||||
// 判断自定义下载
|
||||
if (request.customGetImage !== undefined && typeof request.src === 'string' && (request.src.indexOf("http://") == 0 || request.src.indexOf("https://") == 0)) {
|
||||
if (request.customGetImage !== undefined && request.requestSource == ImageKnifeRequestSource.SRC) {
|
||||
// 先从文件缓存获取
|
||||
resBuf = FileCache.getFileCacheByFile(request.context, fileKey , request.fileCacheFolder)
|
||||
if (resBuf === undefined) {
|
||||
|
@ -417,14 +417,6 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
|
|||
headerObj[key] = value
|
||||
})
|
||||
}
|
||||
let promise = httpRequest.requestInStream(request.src, {
|
||||
header: headerObj,
|
||||
method: http.RequestMethod.GET,
|
||||
connectTimeout: 6000,
|
||||
readTimeout: 6000,
|
||||
// header: new Header('application/json')
|
||||
});
|
||||
|
||||
httpRequest.on("dataReceive", (data: ArrayBuffer) => {
|
||||
arrayBuffers.push(data)
|
||||
});
|
||||
|
@ -451,6 +443,15 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
|
|||
}
|
||||
})
|
||||
}
|
||||
let promise = httpRequest.requestInStream(request.src, {
|
||||
header: headerObj,
|
||||
method: http.RequestMethod.GET,
|
||||
expectDataType: http.HttpDataType.ARRAY_BUFFER,
|
||||
connectTimeout: 6000,
|
||||
readTimeout: 6000,
|
||||
// usingProtocol:http.HttpProtocol.HTTP1_1
|
||||
// header: new Header('application/json')
|
||||
});
|
||||
|
||||
await promise.then((data: number) => {
|
||||
if (data == 200) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import taskpool from '@ohos.taskpool';
|
|||
import common from '@ohos.app.ability.common'
|
||||
import { CacheStrategy, ImageKnifeData,EventImage } from './model/ImageKnifeData';
|
||||
import { PixelMapTransformation } from './transform/PixelMapTransformation';
|
||||
import { drawing } from '@kit.ArkGraphics2D';
|
||||
|
||||
export interface HeaderOptions {
|
||||
key: string;
|
||||
|
@ -52,7 +53,7 @@ export class ImageKnifeOption {
|
|||
transformation?: PixelMapTransformation
|
||||
onLoadListener?: OnLoadCallBack | undefined;
|
||||
onComplete?:(event:EventImage | undefined) => void
|
||||
|
||||
drawingColorFilter?: ColorFilter | drawing.ColorFilter
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
|
|
@ -77,6 +77,7 @@ export struct ImageKnifeComponent {
|
|||
|
||||
build() {
|
||||
Image(this.pixelMap)
|
||||
.colorFilter(this.imageKnifeOption.drawingColorFilter)
|
||||
.objectFit(this.objectFit)
|
||||
.width(this.adaptiveWidth)
|
||||
.height(this.adaptiveHeight)
|
||||
|
|
Loading…
Reference in New Issue