hbuilder 上传图片 保存图片 拍照 muse ui

html


  
    
      拍照
    
    
      从手机相册选择
    
    
      保存图片
    
    
      取消
    
  

js

// 保存图片

saveImg () {
  let self = this
  console.log('图片地址' + self.$store.state.user.icon)
  plus.gallery.save(self.$store.state.user.icon, function () {
    self.$toast.success('保存图片到相册成功')
    self.open = false
  },function(){
    self.$toast.error('保存失败')
  })
},
//拍照
setImg () {
  let self = this
  let cmr = plus.camera.getCamera()
  cmr.captureImage(function (p){
    plus.io.resolveLocalFileSystemURL(p, function(entry){
      self.resolveImg(entry.toLocalURL())
    }, function(e){})
  }, function(e){},{filename: '_doc/camera/'})
},

// 压缩

resolveImg (path) {
  this.open = false
  //图片太大,需要压缩
  let self = this
  let substr = path.substr(path.lastIndexOf("/") + 1)
  plus.io.resolveLocalFileSystemURL (path, function(entry) {
    entry.file(function(file) {
      let imgSize = file.size;
      plus.zip.compressImage({
        src: path,
        dst: '_doc/' + substr,
        width: '100%',
        quality: 100,
        overwrite: true
      }, function(event) {
        console.log("压缩成功-->" + event.target)
        let minImg = event.target
        console.log(minImg)
        self.updateIcon(minImg) // 后台接口方法
      })
    })
  }, function(e) {
    alert("Resolve file URL failed: " + e.message)
  })
},

你可能感兴趣的:(hbuilder 上传图片 保存图片 拍照 muse ui)