自定义下载改为仅支持主图和修改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
|
## 3.0.0-rc.9
|
||||||
- 修复Resource类型$r(变量无法)加载
|
- 修复Resource类型$r(变量无法)加载
|
||||||
|
|
|
@ -277,6 +277,8 @@ ImageKnifeComponent({
|
||||||
| signature | String | 自定义缓存关键字(可选) |
|
| signature | String | 自定义缓存关键字(可选) |
|
||||||
| headerOption | Array<HeaderOptions> | 设置请求头(可选) |
|
| headerOption | Array<HeaderOptions> | 设置请求头(可选) |
|
||||||
| transformation | PixelMapTransformation | 图片变换(可选) |
|
| transformation | PixelMapTransformation | 图片变换(可选) |
|
||||||
|
| drawingColorFilter | ColorFilter | drawing.ColorFilter | 图片变换(可选) |
|
||||||
|
| onComplete | (event:EventImage | undefined) => voi | 颜色滤镜效果(可选) |
|
||||||
| onLoadListener | onLoadStart: () => void、onLoadSuccess: (data: string | PixelMap | undefined) => void、onLoadFailed: (err: string) => void| 监听图片加载成功与失败 |
|
| onLoadListener | onLoadStart: () => void、onLoadSuccess: (data: string | PixelMap | undefined) => void、onLoadFailed: (err: string) => void| 监听图片加载成功与失败 |
|
||||||
|
|
||||||
### ImageKnife接口
|
### ImageKnife接口
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
import { ImageKnifeComponent,BlurTransformation } from '@ohos/libraryimageknife';
|
import { ImageKnifeComponent,BlurTransformation } from '@ohos/libraryimageknife';
|
||||||
import fs from '@ohos.file.fs';
|
import fs from '@ohos.file.fs';
|
||||||
import image from '@ohos.multimedia.image';
|
import image from '@ohos.multimedia.image';
|
||||||
|
import { common2D, drawing } from '@kit.ArkGraphics2D';
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
|
@ -23,6 +24,8 @@ struct SingleImage {
|
||||||
scroller: Scroller = new Scroller;
|
scroller: Scroller = new Scroller;
|
||||||
localFile: string = getContext(this).filesDir + "/icon.png"
|
localFile: string = getContext(this).filesDir + "/icon.png"
|
||||||
@State pixelMap:PixelMap | undefined = undefined;
|
@State pixelMap:PixelMap | undefined = undefined;
|
||||||
|
@State DrawingColorFilter: ColorFilter | undefined = undefined
|
||||||
|
private color: common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
|
||||||
aboutToAppear(): void {
|
aboutToAppear(): void {
|
||||||
// 拷贝本地文件
|
// 拷贝本地文件
|
||||||
let icon: Uint8Array = getContext(this).resourceManager.getMediaContentSync($r("app.media.startIcon"));
|
let icon: Uint8Array = getContext(this).resourceManager.getMediaContentSync($r("app.media.startIcon"));
|
||||||
|
@ -44,12 +47,15 @@ struct SingleImage {
|
||||||
.fontWeight(FontWeight.Bold)
|
.fontWeight(FontWeight.Bold)
|
||||||
ImageKnifeComponent({
|
ImageKnifeComponent({
|
||||||
imageKnifeOption: {
|
imageKnifeOption: {
|
||||||
loadSrc: $r(this.resource),
|
loadSrc: $r("app.media.svgSample"),
|
||||||
placeholderSrc: $r("app.media.loading"),
|
placeholderSrc: $r("app.media.loading"),
|
||||||
errorholderSrc: $r("app.media.failed"),
|
errorholderSrc: $r("app.media.failed"),
|
||||||
objectFit: ImageFit.Contain
|
objectFit: ImageFit.Contain
|
||||||
}
|
}
|
||||||
}).width(100).height(100)
|
}).width(100).height(100)
|
||||||
|
.onClick(()=>{
|
||||||
|
this.DrawingColorFilter = drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN);
|
||||||
|
})
|
||||||
Text("本地context files下文件")
|
Text("本地context files下文件")
|
||||||
.fontSize(30)
|
.fontSize(30)
|
||||||
.fontWeight(FontWeight.Bold)
|
.fontWeight(FontWeight.Bold)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
"main": "index.ets",
|
"main": "index.ets",
|
||||||
"repository": "https://gitee.com/openharmony-tpc/ImageKnife",
|
"repository": "https://gitee.com/openharmony-tpc/ImageKnife",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "3.0.0-rc.10",
|
"version": "3.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ohos/gpu_transform": "^1.0.2"
|
"@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)
|
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)
|
resBuf = FileCache.getFileCacheByFile(request.context, fileKey , request.fileCacheFolder)
|
||||||
if (resBuf === undefined) {
|
if (resBuf === undefined) {
|
||||||
|
@ -417,14 +417,6 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
|
||||||
headerObj[key] = value
|
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) => {
|
httpRequest.on("dataReceive", (data: ArrayBuffer) => {
|
||||||
arrayBuffers.push(data)
|
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) => {
|
await promise.then((data: number) => {
|
||||||
if (data == 200) {
|
if (data == 200) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import taskpool from '@ohos.taskpool';
|
||||||
import common from '@ohos.app.ability.common'
|
import common from '@ohos.app.ability.common'
|
||||||
import { CacheStrategy, ImageKnifeData,EventImage } from './model/ImageKnifeData';
|
import { CacheStrategy, ImageKnifeData,EventImage } from './model/ImageKnifeData';
|
||||||
import { PixelMapTransformation } from './transform/PixelMapTransformation';
|
import { PixelMapTransformation } from './transform/PixelMapTransformation';
|
||||||
|
import { drawing } from '@kit.ArkGraphics2D';
|
||||||
|
|
||||||
export interface HeaderOptions {
|
export interface HeaderOptions {
|
||||||
key: string;
|
key: string;
|
||||||
|
@ -52,7 +53,7 @@ export class ImageKnifeOption {
|
||||||
transformation?: PixelMapTransformation
|
transformation?: PixelMapTransformation
|
||||||
onLoadListener?: OnLoadCallBack | undefined;
|
onLoadListener?: OnLoadCallBack | undefined;
|
||||||
onComplete?:(event:EventImage | undefined) => void
|
onComplete?:(event:EventImage | undefined) => void
|
||||||
|
drawingColorFilter?: ColorFilter | drawing.ColorFilter
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ export struct ImageKnifeComponent {
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Image(this.pixelMap)
|
Image(this.pixelMap)
|
||||||
|
.colorFilter(this.imageKnifeOption.drawingColorFilter)
|
||||||
.objectFit(this.objectFit)
|
.objectFit(this.objectFit)
|
||||||
.width(this.adaptiveWidth)
|
.width(this.adaptiveWidth)
|
||||||
.height(this.adaptiveHeight)
|
.height(this.adaptiveHeight)
|
||||||
|
|
Loading…
Reference in New Issue