zoukankan      html  css  js  c++  java
  • 裁剪一张图 指定宽高 canvas

             // picUrl: 'https://t7.baidu.com/it/u=2458317123,3391822374&fm=193&f=GIF'
    
    
     handleClick () {
          this.clipSrcPic(this.picUrl, result => {
            this.newUrl = result
          })
        },
        clipSrcPic (picUrl, cb) {
          //  target:  380 * 242
          //  srcPic: 716 * 1036
          const picObj = new Image()
          picObj.src = picUrl
          picObj.setAttribute('crossOrigin', '')
          picObj.onload = () => {
            const srcNaturalWidth = picObj.naturalWidth
            const srcNaturalHeight = picObj.naturalHeight
    
            const canvas = document.createElement('canvas')
            console.log('canvas is ...', canvas)
            const ctx = canvas.getContext('2d')
            canvas.width = 380
            canvas.height = 242
    
            const sLeft = srcNaturalWidth / 2 - (280 / 2)
            const sTop = srcNaturalHeight - 242
            ctx.drawImage(picObj, sLeft, sTop, 380, 242, 0, 0, 380, 242)
            //  document.getElementById('Huipage').appendChild(canvas)
            cb(canvas.toDataURL())
            canvas.remove()
            console.log('canvas is ...', canvas)
          }
        }
  • 相关阅读:
    抽象代数学习笔记
    WC2021 游记
    简单的数学题
    前缀和公式
    杜教筛
    [模板]BZOJ4756线段树合并
    SPOJ 694
    bzoj1367 可并堆
    莫比乌斯反演(理论)
    es6 Set数据结构
  • 原文地址:https://www.cnblogs.com/dhjy123/p/15574432.html
Copyright © 2011-2022 走看看