import common from '@ohos.app.ability.common';
import picker from '@ohos.file.picker';
@Entry
@Component
struct pickerDemo {
@State getImg: string = '获取图片'
@State imgArr: string[] = []
getPhotoImg() {
let photoPicker = new picker.PhotoViewPicker();
photoPicker.select({
MIMEType: picker.PhotoViewMIMETypes.IMAGE_TYPE,
maxSelectNumber: 3
}, (err, data) => {
if (err) {
console.info("photoPicker:" + err.message)
return
}
this.imgArr = data.photoUris
console.log("photoPicker:" + JSON.stringify(data))
data.isOriginalPhoto
})
}
build() {
Column() {
ForEach(this.imgArr, (item: string, index: number) => {
Row() {
Image(item).width(100).height(100).borderWidth(1)
}
})
Button(this.getImg).margin(20)
.onClick(() => {
this.getPhotoImg()
})
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
}
可以通过PhotoKeys获取文件信息,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-photoaccesshelper-V5\#ZH-CN\_TOPIC\_0000001930677569\_\_photokeys