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

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

阅读 680
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%'
    )
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进