中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
微信扫码分享
import { picker } from '@kit.CoreFileKit'; import photoAccessHelper from '@ohos.file.photoAccessHelper'; import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component struct Index9 { @State selectedUri: string = ''; choosePhoto() { try { let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; PhotoSelectOptions.maxSelectNumber = 5; PhotoSelectOptions.isEditSupported = true; PhotoSelectOptions.isPhotoTakingSupported = true; let photoPicker = new picker.PhotoViewPicker() let uris: Array<string> = []; photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); uris = PhotoSelectResult.photoUris; this.selectedUri = uris[0]; }).catch((err: BusinessError) => { console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); }); } catch (error) { let err: BusinessError = error as BusinessError; console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`); } } build() { Row() { Column({ space: 30 }) { Button('选择图片') .width(200) .height(30) .onClick(() => { this.choosePhoto() }) Image(this.selectedUri) .width('95%') .height(400) .padding({top:'30xp'}) } .width('100%') .height('100%') } .height('100%') } }