文字居中:ctx.textAlign = "center";
元素居中:ctx.arc(screenWidth / 2, 122, 40, 0, 2 * Math.PI);
ctx.arc()的x轴为当前屏幕的宽度/2;
let screenWidth = 540;
let screenHeight = 960;
// 头像
if (photoimg) {
ctx.setFillStyle('#000000')
ctx.save();
ctx.beginPath() //开始创建一个路径
ctx.arc(screenWidth / 2, 122, 40, 0, 2 * Math.PI) //画一个圆形裁剪区域
ctx.strokeStyle = 'transparent';
ctx.stroke();
ctx.clip() //裁剪
ctx.drawImage(photoimg, 230, 82, 80, 80);
ctx.restore()
}
// 昵称
if (that.userInfo) {
let names = that.userInfo.nickname
ctx.setFontSize(28);
ctx.setFillStyle('#333333')
ctx.font = 'normal blod 28px PingFangSC, PingFang SC';
ctx.textAlign = "center"
let titleW = ctx.measureText(names)
ctx.fillText(names, screenWidth / 2, 196);
}