HarmonyOS 如何调用本地相册并选取图片?

HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

可以参考demo:

import { BusinessError } from '@ohos.base';
import photoAccessHelper from '@ohos.file.photoAccessHelper';

@Entry
@Component
struct Photo_Access {
  build() {
    Button('访问手机相册').onClick(() => {
      try {
        let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
        PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;
        PhotoSelectOptions.maxSelectNumber = 5;
        let photoPicker = new photoAccessHelper.PhotoViewPicker();
        photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => {
          console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' +
          JSON.stringify(PhotoSelectResult));
        }).catch((err: BusinessError) => {
          console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err));
        });
      } catch (error) {
        let err: BusinessError = error as BusinessError;
        console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
      }
    })
  }
}
分享
微博
QQ
微信
回复
1天前
相关问题
HarmonyOS 图片资源选取
462浏览 • 1回复 待解决
HarmonyOS 保存图片本地相册
22浏览 • 1回复 待解决
HarmonyOS选取拷贝文件失败
439浏览 • 1回复 待解决
如何保存本地图片相册
1130浏览 • 1回复 待解决
如何调用系统拍照获取图片
707浏览 • 1回复 待解决
获取网络图片保存到相册
1534浏览 • 1回复 待解决
HarmonyOS H5页面保存图片本地相册
37浏览 • 1回复 待解决