文件保存操作

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)
       }
     })
  },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值