HarmonyOS如何打开手机相册

HarmonyOS如何打开手机相册

HarmonyOS
2024-08-22 20:15:49
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect
import { BusinessError } from '@ohos.base'; 
import { picker } from '@kit.CoreFileKit'; 
async function example03() { 
  try { 
    let photoPicker = new picker.PhotoViewPicker(); 
    photoPicker.select((err: BusinessError, PhotoSelectResult: picker.PhotoSelectResult) => { 
      if (err) { 
        console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); 
        return; 
      } 
      console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); 
    }); 
  } catch (error) { 
    let err: BusinessError = error as BusinessError; 
    console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 
  } 
} 
@Entry 
@Component 
struct PhotoViewPicker { 
  @State message: string = 'Hello World'; 
  build() { 
    Row() { 
      Column() { 
        Button('PhotoPick') 
          .onClick(() => { 
            example03(); 
          }) 
          .margin({right:12}) 
          .margin({top:20}) 
          .width(150) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}

保存图片参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/save-user-file-0000001774120434-V5选择的图片返回的uri是这个:PhotoSelectResult.photoUris。

分享
微博
QQ
微信
回复
2024-08-23 17:40:22
相关问题
HarmonyOS 如何拉起手机相册
313浏览 • 1回复 待解决
HarmonyOS 如何打开系统相册页面
452浏览 • 1回复 待解决
HarmonyOS如何把图片保存到手机相册
518浏览 • 1回复 待解决
HarmonyOS 如何打开应用?
229浏览 • 2回复 待解决
HarmonyOS H5如何访问相册
284浏览 • 1回复 待解决
HarmonyOS如何将PixelMap保存到相册
580浏览 • 1回复 待解决