收藏
回答

【已解决】drawImage图像到画布比例问题

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug drawImage 工具 7 262

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

最后一次编辑于  2019-03-20
回答关注问题邀请回答
收藏

2 个回答

  • 禾店短剧系统
    禾店短剧系统
    2021-06-09

    这是因为您在Image(width, height)构造函数中将其设置为image的宽度和高度属性,从而对其进行了硬编码。

    ctx.drawImage(img, dx, dy [, dwidth ,dheight])将使swidthsheight默认为你的形象的naturalWidthnaturalHeight,而不是他们的widthheight的。


    2021-06-09
    有用 1
    回复
  • Kevin
    Kevin
    2019-03-20

    答案

    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)


    2019-03-20
    有用
    回复
登录 后发表内容