HarmonyOS @ohos/imageknife使用RoundedCornersTransformation时,圆角尺寸设置问题和样式显示问题?

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 })
    }
  }
}
阅读 437
1 个回答

规避方案来解决该问题:可以在ImageKnifeComponent组件外再套一层容器进行裁剪实现圆角效果。示例代码:

Row() {
  ImageKnifeComponent({
    imageKnifeOption: {
      loadSrc: $r("app.media.1000"),
      mainScaleType: ScaleType.FIT_XY
    }
  }).width(300).height(300)
}.borderRadius(50).clip(true)
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进