HarmonyOS【ArkUI组件---Image组件】

1.实现效果

2.Image:图片显示组件

3.通过网络图片

javascript 复制代码
@Entry
@Component
struct Index {
  @State message: string = 'Hello World'

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .fontColor('#36D')
          .onClick(()=>{
            this.message='Hello ArkTS!'
          })
        Image('https://res.vmallres.com/uomcdn/CN/cms/202406/2db7e1ea3fbf40fbac8adce59b04f44d.png')
          .width(250)
      }

      .width('100%')
    }
    .height('100%')
  }
}

4.网络访问权限

当我们没有配置权限的时候,只能在预览器中看见网络图片,在模拟器上不可以

打开module.json5文件

javascript 复制代码
 "requestPermissions": [
      {
        "name":"ohos.permission.INTERNET"
      }
    ],

添加之后,效果如下图所示 :

5.本地图片

javascript 复制代码
 Image($r('app.media.app_icon'))
          .width(250)
          .interpolation(ImageInterpolation.High)
相关推荐
ONEDAY18 小时前
HarmonyOS 多 Product 构建实践:一套代码生成多个产物
harmonyos
TT_Close20 小时前
别劝退了!5秒搞定 Flutter 鸿蒙 FVM 起跑线
flutter·harmonyos·visual studio code
TrisighT1 天前
ArkTS 列表滚动时为什么会闪现旧数据?我扒了 LazyForEach 的复用逻辑
harmonyos·arkts·arkui
MonkeyKing1 天前
鸿蒙ArkTS深度剖析:ArkTS与TS/JS核心差异、静态强类型实战优势
typescript·harmonyos
TrisighT1 天前
Electron鸿蒙PC上写日志文件,我被权限和路径坑了两次
electron·harmonyos
TrisighT2 天前
一个下午搞定 ArkTS 折叠面板?结果我从两点写到晚上九点
harmonyos·arkts·arkui
花椒技术5 天前
HJPusher / HJPlayer SDK 实践:我们为什么把直播推播链路拆成一套可复用能力
设计模式·harmonyos·直播
一维Ace5 天前
HarmonyOS ArkTS 按钮组件全解:Button、Toggle 状态交互实战
harmonyos
anyup6 天前
来简单聊聊鸿蒙开发,万元奖金的事~
前端·华为·harmonyos
Georgewu6 天前
【无测试机别害怕】华为云鸿蒙云手机南:从零到联调全流程详解
harmonyos