【已解决】drawImage图像到画布比例问题
发布于 5 年前 作者 baiping 7353 次浏览 来自 问答

使用drawImage接口把一个100 * 100的图像画到一个50 * 50的画布怎么按比例缩放,让图像全部显示在画布

1 回复

答案

ctx.save();
  let sx = 111
  let sy = 180
  let headWidth = 80
  let headHeight = 80
  let headX = (headWidth / 2) + sx
  let headY = (headHeight / 2) + sy
  ctx.arc(headX, headY, headHeight / 2, 0, Math.PI * 2, false);
  ctx.clip();
  ctx.drawImage(image, sx, sy, headWidth, headHeight);
  // ctx.restore();
  ctx.draw(true)
回到顶部