账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    canvas图片旋转之后在拖动,坐标系应该怎么转换?
    20
    0

    图片不旋转的时候可以直接拖动,图片如果旋转过了,坐标系就会变掉,再次拖动的话,怎么判断坐标系是在原点还是已经变过了的呢?
    cvsMove: function (e) {

    if (e.touches.length > 1) {//二指缩放
    console.log("双指缩放")
    var xMove2 = Math.abs(e.touches[1].x - e.touches[0].x);
    var yMove2 = Math.abs(e.touches[1].y - e.touches[0].y);
             var distance2 = Math.sqrt(xMove2 * xMove2 + yMove2 * yMove2);//开根号
             console.log(distance2);
            //  this.data.distanceList.shift()
            //  this.data.distanceList.push(distance)
            //  if (this.data.distanceList[0] == 0) { return }
            //  var distanceDiff = this.data.distanceList[1] - this.data.distanceList[0]//两次touch之间, distance的变化. >0,放大图片.<0 缩小图片
            //  var baseScale = 1 + 0.005 * distanceDiff
             var baseScale = this.data.distance1 / distance2 ;
             console.log("缩放率"+baseScale);
             const ctx = wx.createCanvasContext('myCanvas');
             ctx.scale(baseScale, baseScale);
             ctx.drawImage(this.data.tempFilePaths, this.data.lastX, this.data.lastY, 200 , 300);
            
             ctx.restore();
    } else if (e.touches.length == 1){
      var touchs = e.touches[0];
      console.log('canvas被拖动了....')
      var x = touchs.x;
      var y = touchs.y;
      var moveX = x - this.data.currentX;
      var moveY = y - this.data.currentY;
      this.setData({
        newX : this.data.lastX + moveX,
        newY : this.data.lastY + moveY
      })
      const ctx = wx.createCanvasContext('myCanvas');
      ctx.save();
      ctx.setFillStyle('white');
      ctx.drawImage(this.data.tempFilePaths, this.data.newX, this.data.newY, 200, 300)
      ctx.draw();
      ctx.restore();
    }

    },

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部