camera组件查询: https://www.w3cschool.cn/weixinapp/weixinapp-fxj12j2z.html
wxml代码
摄像头后置,不开启闪光
<camera divice-position="back" flash="off" style="width:100%;height:300px"></camera>
<button type="primary" bindtap="takePhoto">拍照</button>
<button bindtap="save">保存按钮</button>
<button bindtap="savedList">查看存储在本地的文件列表</button>
<button bindtap="savedFileInfo">已经存储在那的地址</button>
文件文档: https://www.w3cschool.cn/weixinapp/weixinapp-file.html
js代码:
拍照操作,保存在缓存文件中
var tempPath="" 定义缓存文件路径
takePhoto:function(){
this.ctx.takePhoto({
quality:"high",
success:function(res){
tempPath=res.tempImagePath
console.log(tempPath)
//读取临时的缓存文件
wx.getFileInfo({
filePath: 'tempPath',
success(e){
console.log(e)
}
})
}
})
},
保存图片:
save:function(){
//确保已经有文件在缓存中
wx.saveFile({
tempFilePath: tempPath,
success:function(res){
console.log(res)
},
fail:function(res){
console.log(res)
}
})
},
保存多张图片列表,点击按钮多次
savedList:function(){
wx.getSavedFileList({
success(res){
console.log(res.fileList)
savedFileList = res.fileList
}
})
}
保存文件列表中的某一个图片信息
savedFileInfo:function(){
wx.getSavedFileInfo({
filePath: savedFileList[0].filePath,
success:function(res){
console.log(res)
}
})
},