通过picker选择图片后,返回file://***协议,如何通过Image展示?

通过picker选择图片后,返回file://***协议,如何通过Image展示?

HarmonyOS
2024-06-05 21:01:00
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
每天睡满八小时

开发者您好,可以直接通过Image展示,示例代码:

import picker from '@ohos.file.picker'; 
 
@Entry 
@Component 
struct Index { 
  @State imagePath: string = '' 
  ; 
 
  build() { 
    Column() { 
      Button('select') 
        .onClick(() => { 
          let PhotoSelectOptions = new picker.PhotoSelectOptions(); 
          PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; 
          PhotoSelectOptions.maxSelectNumber = 5; 
          let photoPicker = new picker.PhotoViewPicker(); 
          photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => { 
            this.imagePath = PhotoSelectResult.photoUris?.[0] ?? ''; 
          }) 
        }) 
      Image(this.imagePath) 
        .width(100) 
    } 
    .width('100%' 
    ) 
  } 
}
分享
微博
QQ
微信
回复
2024-06-06 21:24:20
相关问题
HarmonyOS Image展示本地图片失败
29浏览 • 1回复 待解决