zoukankan      html  css  js  c++  java
  • 上传图片

        // 上传头像
        uploadPhoto (e) {
          let fileObj = e.target.files[0]
          let reader = new FileReader()
          reader.readAsDataURL(fileObj)
          reader.onloadend = e => {
            let result = e.target.result
            this.headPortraitSrc = result
            this.defalutPhotoVisible = false
            if (result.size <= 200 * 1024) {
              // 小于两兆直接上传
            } else {
              // 大于两兆压缩后上传
              let imgObj = e.target
              imgObj.onload = () => {
              }
              console.log()
            }
          }
        },
        // 压缩图片
        compressImg (img) {
          let canvas = document.createElement('canvas')
          let ctx = canvas.getContext('2d')
          canvas.width = img.width
          canvas.height = img.height
          ctx.fillStyle = '#fff'
          ctx.fillRect(0, 0, canvas.width, canvas.height)
          ctx.drawImage(img, 0, 0, img.width, img.height)
          return canvas.toDataURL('image/jpeg', 0.5)
        },
        // [transformBaseToBlob base64转成bolb对象]
        transformBaseToBlob (base64Data) {
          let arr = base64Data.split(',')
          let mimeType = arr[0].match(/:(.*?);/)[1]
          let bstr = atob(arr[1])
          let len = bstr.length
          let u8arr = new Uint8Array(len)
          while (len--) {
            u8arr[len] = bstr.charCodeAt(len)
          }
          return new Blob([u8arr], { type: mimeType })
        },
    

      

  • 相关阅读:
    JQuery使用总结
    JS应用总结
    Base64数据转成Excel,并处理Excel的格式
    HTTP压缩
    谷歌开发工具解析
    .Net LIst排重
    MySql日志系统
    .Net生成PDF流
    Mysql MVCC
    JAVA期末综合课程设计
  • 原文地址:https://www.cnblogs.com/liumengdie/p/10318512.html
Copyright © 2011-2022 走看看