1、在"2.1.2-rc.7"版本下,设置的圆角尺寸是按照图片本身的分辨率来的,但实际一般应用中,圆角的尺寸设置都是针对图片显示容器的尺寸的,而不是根据图片的像素尺寸。
2、在"2.1.2-rc.7"版本下,给显示的图片设置圆角,则圆角位置会显示异常。若改变圆角的值,异常也会变化。
代码如下:
@Entry
@Component
export struct TestDemo {
@State corner: number = 100
build() {
Column() {
Text(`当前圆角尺寸:${this.corner}`)
.height(50)
.width('100%')
.textAlign(TextAlign.Center)
.backgroundColor(0x880000ff)
Row() {
Text(`点击尺寸加50`)
.onClick(() => {
this.corner = this.corner + 50
})
.width('50%')
.backgroundColor(0x88ff0000)
.textAlign(TextAlign.Center)
.height(50)
Text(`点击尺寸减50`)
.onClick(() => {
this.corner = Math.max(this.corner - 50, 0)
})
.width('50%')
.backgroundColor(0x8800ff00)
.textAlign(TextAlign.Center)
.height(50)
}.height(50).width('100%')
ImageKnifeComponent({
imageKnifeOption: {
mainScaleType: ScaleType.CENTER_CROP,
loadSrc: 'https://***.jpg',
}
})
.width(200).height(250).margin({ top: 10 })
ImageKnifeComponent({
imageKnifeOption: {
transformation: new RoundedCornersTransformation({
top_left: this.corner,
top_right: this.corner,
bottom_left: this.corner,
bottom_right: this.corner
}),
mainScaleType: ScaleType.CENTER_CROP,
loadSrc: 'https://***.jpg',
}
})
.width(200).height(250).margin({ top: 10 })
}
}
}
规避方案来解决该问题:可以在ImageKnifeComponent组件外再套一层容器进行裁剪实现圆角效果。示例代码: