64 lines
2.2 KiB
Plaintext
64 lines
2.2 KiB
Plaintext
/*
|
||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||
* Licensed under the Apache License, Version 2.0 (the 'License');
|
||
* you may not use this file except in compliance with the License.
|
||
* You may obtain a copy of the License at
|
||
*
|
||
* http://www.apache.org/licenses/LICENSE-2.0
|
||
*
|
||
* Unless required by applicable law or agreed to in writing, software
|
||
* distributed under the License is distributed on an 'AS IS' BASIS,
|
||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
* See the License for the specific language governing permissions and
|
||
* limitations under the License.
|
||
*/
|
||
import { ImageKnifeComponent, ImageKnife, ImageKnifeOption } from '@ohos/libraryimageknife'
|
||
|
||
@Entry
|
||
@ComponentV2
|
||
struct TestSetCustomImagePage {
|
||
@Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
|
||
loadSrc: $r('app.media.startIcon'),
|
||
placeholderSrc: $r('app.media.loading')
|
||
})
|
||
aboutToAppear(): void {
|
||
ImageKnife.getInstance().setCustomGetImage(custom)
|
||
}
|
||
aboutToDisappear(): void {
|
||
ImageKnife.getInstance().setCustomGetImage()
|
||
}
|
||
build() {
|
||
Column() {
|
||
Button("自定义下载a").onClick(()=>{
|
||
this.imageKnifeOption = new ImageKnifeOption({
|
||
loadSrc: "aaa",
|
||
placeholderSrc: $r('app.media.loading')
|
||
})
|
||
})
|
||
Button("自定义下载b").onClick(()=>{
|
||
this.imageKnifeOption = new ImageKnifeOption({
|
||
loadSrc: "bbb",
|
||
placeholderSrc: $r('app.media.loading')
|
||
})
|
||
})
|
||
Button("自定义下载c").onClick(()=>{
|
||
this.imageKnifeOption = new ImageKnifeOption({
|
||
loadSrc: "ccc",
|
||
placeholderSrc: $r('app.media.loading')
|
||
})
|
||
})
|
||
ImageKnifeComponent({
|
||
imageKnifeOption: this.imageKnifeOption
|
||
}).width(300)
|
||
.height(300)
|
||
}
|
||
.width("100%")
|
||
.height("100%")
|
||
}
|
||
}
|
||
@Concurrent
|
||
async function custom(context: Context, src: string | PixelMap | Resource): Promise<ArrayBuffer | undefined> {
|
||
console.info("ImageKnife:: custom download:" + src)
|
||
// 举例写死从本地文件读取,也可以自己请求网络图片
|
||
return context.resourceManager.getMediaContentSync($r("app.media.pngSample").id).buffer as ArrayBuffer
|
||
} |