右键单击和鼠标移动如何在画布内执行缩放操作

时间:2019-01-24 04:34:43

标签: typescript angular6

让currX = e.offsetX || (e.pageX-this.canvasx);       让currY = e.offsetY || (e.pageY-this.canvasy);

  let posX = this.prevX - currX;
  let posY = this.prevY - currY;
  console.log('Position Y value :' + posY);

  if (posY > 0) {

    // Compute zoom factor.
    var zoom = Math.exp(posY * this.scaleFactor);
    // Translate so the visible origin is at the context's origin.
    this.ctx.translate(currX, currY);
    console.log('current zoom value on Y- axis increasing' + zoom)



    this.ctx.scale(zoom, zoom);
    this.redraw(this.ctx);
    this.drawLines(this.ctx);

  } else if (posY < 0) {

    var zoom = Math.exp(posY * this.scaleFactor);
    console.log('current zoom value on Y- axis decreasing' + zoom)


    this.ctx.translate(currX, currY);
    this.ctx.scale(zoom, zoom);
    this.redraw(this.ctx);
    this.drawLines(this.ctx);
  }

上面给出的代码是在画布中执行缩放的示例,在这里我将两个画布背景用于图像lod,将其他画布背景用于绘制形状。

0 个答案:

没有答案