//创建画布
ctx.fillStyle = '#fff'
ctx.fillRect(0, 0, this.config.maxWidth, this.config.maxHeight)
//获取宽度
var txt='今天天气很好'
var wid_1 = ctx.measureText(txt).width
console.log(wid_1, 'wid_1')
//打印 144 "wid_1"
Canvas 获取文本宽度使用ctx.measureText
最新推荐文章于 2024-03-06 10:19:07 发布