98 lines
3.6 KiB
Plaintext
98 lines
3.6 KiB
Plaintext
/*
|
|
* Copyright (C) 2022 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 {
|
|
ImageKnifeComponent,
|
|
ImageKnifeOption,
|
|
ImageKnifeDrawFactory,
|
|
ScaleType
|
|
} from '@ohos/libraryimageknife'
|
|
|
|
@Entry
|
|
@Component
|
|
struct DrawFactoryTestPage {
|
|
|
|
types:Array<ScaleType> = [ScaleType.FIT_START,ScaleType.FIT_END,ScaleType.FIT_CENTER,ScaleType.CENTER,ScaleType.CENTER_CROP,ScaleType.FIT_XY,ScaleType.CENTER_INSIDE,ScaleType.NONE]
|
|
|
|
|
|
@State msg:string = `当前ScaleType${this.types[0]}`
|
|
|
|
@State imageKnifeOption1: ImageKnifeOption =
|
|
{
|
|
loadSrc:"https://xximg1.meitudata.com/2LqS1vmqv0.png!thumb-w321-webp75",
|
|
mainScaleType: this.types[0],
|
|
placeholderSrc: $r('app.media.icon_loading'),
|
|
errorholderSrc: $r('app.media.icon_failed'),
|
|
drawLifeCycle:ImageKnifeDrawFactory.createOvalLifeCycle(15,'#ff000000')
|
|
}
|
|
@State imageKnifeOption2: ImageKnifeOption =
|
|
{
|
|
loadSrc:"https://xximg1.meitudata.com/2LqS1vmqv0.png!thumb-w321-webp75",
|
|
mainScaleType: this.types[0],
|
|
placeholderSrc: $r('app.media.icon_loading'),
|
|
errorholderSrc: $r('app.media.icon_failed'),
|
|
drawLifeCycle:ImageKnifeDrawFactory.createRoundLifeCycle(10,'#ff000000',30)
|
|
}
|
|
|
|
count:number = 0;
|
|
|
|
|
|
build() {
|
|
Scroll() {
|
|
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
|
|
|
|
|
Text("用例看护DrawFactory").fontSize(15)
|
|
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
|
Button(this.msg)
|
|
.onClick(() => {
|
|
this.count++;
|
|
let index= this.count % this.types.length;
|
|
this.msg = `当前ScaleType${this.types[index]}`
|
|
|
|
this.imageKnifeOption1 = {
|
|
loadSrc:"https://xximg1.meitudata.com/2LqS1vmqv0.png!thumb-w321-webp75",
|
|
mainScaleType: this.types[index],
|
|
placeholderSrc: $r('app.media.icon_loading'),
|
|
errorholderSrc: $r('app.media.icon_failed'),
|
|
drawLifeCycle:ImageKnifeDrawFactory.createOvalLifeCycle(15,'#ff000000')
|
|
}
|
|
|
|
this.imageKnifeOption2 = {
|
|
loadSrc:"https://xximg1.meitudata.com/2LqS1vmqv0.png!thumb-w321-webp75",
|
|
mainScaleType: this.types[index],
|
|
placeholderSrc: $r('app.media.icon_loading'),
|
|
errorholderSrc: $r('app.media.icon_failed'),
|
|
drawLifeCycle:ImageKnifeDrawFactory.createRoundLifeCycle(10,'#ff000000',30)
|
|
}
|
|
}).margin({ top: 15, bottom:15 })
|
|
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).width('100%').height(300).backgroundColor(Color.Orange)
|
|
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 }).width('100%').height(300).backgroundColor(Color.Orange)
|
|
.margin({ top: 15, bottom:15 })
|
|
}
|
|
.width('100%').height('100%').backgroundColor(Color.Pink)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}.width('100%')
|
|
}
|
|
.width('100%')
|
|
.height('100%')
|
|
}
|
|
|
|
} |