中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何拉起选择图片的界面,并选择图片、视频?
微信扫码分享
import picker from '@ohos.file.picker'; /** * 通过选择模式拉起PhotoViewPicker界面,用户可以选择一个或多个图片/视频。 * @param options * @returns */ static async selectPhoto(options?: picker.PhotoSelectOptions): Promise<Array<string>> { try { if (!options) { options = new picker.PhotoSelectOptions(); } if (!options.MIMEType) { //可选择的媒体文件类型,若无此参数,则默认为图片和视频类型。 options.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; } if (!options.maxSelectNumber) { //选择媒体文件数量的最大值,默认9 options.maxSelectNumber = DOCUMENT_DEFAULT_SELECT_NUMBER; } let photoPicker = new picker.PhotoViewPicker(); let photoSelectResult: picker.PhotoSelectResult = await photoPicker.select(options); if (photoSelectResult && photoSelectResult.photoUris && photoSelectResult.photoUris.length > 0) { return photoSelectResult.photoUris; } else { return []; } } catch (err) { let error = err as BusinessError; LogUtil.error(`PickerUtil-selectPhoto-异常 ~ code: ${error.code} -·- message: ${error.message}`); return []; } }