// 获取画布
var c = document.querySelector('canvas');
// 获取绘图对象
var ctx = c.getContext('2d');
// 绘制文本 像素 字体
ctx.font="50px 宋体";
// 设置文本对齐方式 left | center | right
ctx.textAlign = 'center';
// 设置文本上下对齐方式 top | middle | bottom | alphabetic(默认)
ctx.textBaseline = 'middle';
// 设置阴影颜色
ctx.shadowColor = 'red';
// 阴影水平偏移量
ctx.shadowOffsetx = 15;
// 阴影垂直偏移量
ctx.shadowOffsety = 15;
// 阴影模糊度
ctx.shadowBlur = 5;
// 镂空效果 内容 坐标
ctx.strokeText('你好', 100, 100);
// 填充文本
ctx.fillText('你好', 100, 100);
Canvas绘制文本
最新推荐文章于 2021-02-16 21:14:40 发布