这是利用背景填充,原理跟ps里面剪贴蒙版效果一致
运行效果:
代码示例:
代码示例:
使用图片作为背景填充文本
maxlen当长度不足时会压缩文字宽度
strokeText可以给文本描边
设置字体,然后调用fillText函数绘制文字
context.font = "bold 40px Arial"(粗框,40px大小,字体)
context.fillStyle="#058"颜色
context.fillText(string,x,y,[maxlen](文字的最长宽度))
context.strokeText(string,x,y,[maxlen])(只有外边框的文字)
context.font = "bold 40px Arial"(粗框,40px大小,字体)
context.fillStyle="#058"颜色
context.fillText(string,x,y,[maxlen](文字的最长宽度))
context.strokeText(string,x,y,[maxlen])(只有外边框的文字)