赞
踩
首先要导入内置的模块
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%") } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。