鸿蒙Harmony OS Next原生开发原生UI组件图片缩放和图片插值

鸿蒙初开,开天辟地

图片缩放

当图片的原始大小和Image组件不同时,通过objectFit()方法传入ImageFit的枚举类型来设置图片的显示效果

None,保持原有的尺寸显示,超出显示范围的内容丢弃

Contain,保持宽高比进行缩小放大,让显示区域包含整个图片

Cover保持宽高比进行放大缩小,使图片完全覆盖显示区域

Fill不保持进行放大缩小,使得图片充满显示区域

ScaleDown保持图片宽高比缩小或不变,使图片完全显示在区域内

Auto自适应

 

图片缩放

图片插值

当原始图片分辨率较低且需要放大显示,图片会模糊并出现锯齿

这时使用interpolation方法对图片进行插值会使得图片更清晰

这是一个相当常用的算法

它本质上是基于原有的像素去插入新的像素,让图片的过渡更加平滑

interpolation.None不使用图片插值

interpolation.High高质量插值,会影响图片渲染的速度

interpolation.Medium中等质量

interpolation.Low低质量插值

 

@Component
export default struct See {
  @State options:string[] = ["JAVA","Python","C#","Golang"];
  @State answer:string = "____";
  build() {
    Column({space:20}){
      Row(){
        Text("江河浩瀚,胡生可安").fontSize(25).fontWeight(FontWeight.Bold);
        Text(this.answer).fontSize(25).fontWeight(FontWeight.Bold);
      };
      Image($r('app.media.background')).height('75px').width('75px');
      Image($rawfile('123.png')).height('25vp').width('25vp');
      Button({type:ButtonType.Circle}){
        Text("ArkTS")
      }.onClick(()=>{
        // this.options = ["JAVA","Python","C#","Golang","ArkTs"];
        this.options.push("ArkTs");
      }).width(50).height(50);
      ForEach(this.options,(item:string) => {
        Button(item).width(100).backgroundColor(Color.Red).onClick(()=>{
          this.answer = item;
        });
      },((item:string)=>
          JSON.stringify(item)
      ));
    }
  }
}

@Component
export default struct See {
  @State options:string[] = ["JAVA","Python","C#","Golang"];
  @State answer:string = "____";
  build() {
    Column({space:20}){
      Row(){
        Text("江河浩瀚,胡生可安").fontSize(25).fontWeight(FontWeight.Bold);
        Text(this.answer).fontSize(25).fontWeight(FontWeight.Bold);
      };
      Image($r('app.media.background')).height('75px').width('75px');
      Image($rawfile('123.png')).height('25vp').width('25vp');
      Button({type:ButtonType.Circle}){
        Text("ArkTS")
      }.onClick(()=>{
        // this.options = ["JAVA","Python","C#","Golang","ArkTs"];
        this.options.push("ArkTs");
      }).width(50).height(50);
      ForEach(this.options,(item:string) => {
        Button(item).width(100).backgroundColor(Color.Red).onClick(()=>{
          this.answer = item;
        });
      },((item:string)=>
          JSON.stringify(item)
      ));
    }
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值