canvas fillText 渲染的位置错误
发布于 4 年前 作者 bmeng 13328 次浏览 来自 问答

canvas 导出图片发现 渲染出来的文字位置会出错

代码如下:

ctx.setFontSize(fontSize)
for (let i = 0, height = valY; i < this.scores.length; i++) {
  height += fontSize * 2.2
  let item = this.scores[i]
 
  ctx.setTextAlign('left')
  ctx.fillText(item.team_cn, countryLeft, height)
 
  ctx.setTextAlign('center')
  ctx.fillText(`${item.count}场`, countLeft, height)
 
  ctx.setTextAlign('right')
  ctx.fillText(item.score, scoreLeft, height)
}

效果:

1 回复

楼主问题解决了吗?

回到顶部