当前位置:   article > 正文

鸿蒙调用手机摄像头以及手机本地图库

鸿蒙调用手机摄像头以及手机本地图库

鸿蒙笔记

调用手机摄像头以及手机本地图库

首先要导入内置的模块

import common from '@ohos.app.ability.common'
import wantConstant from '@ohos.ability.wantConstant'
import picker from '@ohos.file.picker'

接下来就尽情的复制粘贴

struct PicTure {
  @State message :string = 'hello'
  @State uri :string = ''
  private context = getContext(this) as common.UIAbilityContext
​
  build(){
    Row(){
      Column(){
        Button('拍照')
          .onClick(async ()=>{
            let wantObj = {
              deviceId:"",
              action:wantConstant.Action.ACTION_IMAGE_CAPTURE
            }
            let data = await this.context.startAbilityForResult(wantObj)
            console.log(data.want.uri)
            this.uri = data.want.uri
          })
        Button('选择图片')
          .onClick(async ()=>{
           let phoToSelectOptions = new picker.PhotoSelectOptions()
            phoToSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE
            phoToSelectOptions.maxSelectNumber = 1
            let photoPicker = new picker.PhotoViewPicker()
            let res = await photoPicker.select(phoToSelectOptions)
            console.log(res.photoUris[0])
​
            this.uri = res.photoUris[0]
          })
        Image(this.uri).size({width:200})
      }
      .width("100%")
    }
    .height("100%")
  }
}
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/317477
推荐阅读
相关标签
  

闽ICP备14008679号