HarmonyOS 如何拉起手机相册?

HarmonyOS  如何拉起手机相册。

HarmonyOS
2024-11-01 09:12:39
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa
// PictureSaving.ets 
import { picker } from '@kit.CoreFileKit'; 
import { BusinessError } from '@kit.BasicServicesKit'; 
import Logger from './Logger'; 
// 定义一个URI数组,用于接收PhotoViewPicker返回的用于选择图像的URI。 
let uris: Array<string> = []; 
// 调用PhotoViewPicker.select选择图片。 
export async function photoPickerGetUri(): Promise<string> { 
  try { 
    let PhotoSelectOptions = new picker.PhotoSelectOptions(); 
    PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; 
    PhotoSelectOptions.maxSelectNumber = 1; 
    let photoPicker = new picker.PhotoViewPicker(); 
    await photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: picker.PhotoSelectResult) => { 
      Logger.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); 
      uris = PhotoSelectResult.photoUris; 
    }).catch((err: BusinessError) => { 
      Logger.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); 
    }); 
  } catch (error) { 
    let err = error as BusinessError; 
    Logger.error('PhotoViewPicker failed with err: ' + err.message); 
  } 
  return uris[0].toString(); 
}

​参考文档:​https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-file-picker-V5#photoviewpicker

分享
微博
QQ
微信
回复
2024-11-01 17:52:31
相关问题
HarmonyOS如何打开手机相册
332浏览 • 1回复 待解决
拉起相册选择图片页面失败
1950浏览 • 1回复 待解决
HarmonyOS如何把图片保存到手机相册
518浏览 • 1回复 待解决
HarmonyOS 如何拉起应用市场?
255浏览 • 1回复 待解决
HarmonyOS 如何打开系统相册页面
450浏览 • 1回复 待解决
HarmonyOS H5如何访问相册
281浏览 • 1回复 待解决