canvas 画布 文字描边

总结一下,canvas 画布 文字描边的2种方法以及其不同的视觉效果:

 

效果图:

 

具体代码:

<canvas id="canvas" width="800" height="440" style="background:black;"></canvas>
<script>
    var c = document.getElementById("canvas"),
        ctx = c.getContext("2d");

    //先设置文字字体和大小
    ctx.font = "4.2rem Open Sans,Microsoft YaHei";
//设置画笔(绘制线条)操作的线条宽度,非必须;如果不写这句,那就是默认1 ctx.lineWidth = 3;
//实线文字 ctx.fillStyle = "green"; ctx.fillText("实线(实心)文字:fill",10,100); //空心文字 ctx.strokeStyle = "red"; ctx.strokeText("空心文字:stroke",10,200); //描边文字:实线与空心文字合起来就是描边啦!先写空心的和先写实心的视觉效果不同: //1.空心+实心 ctx.strokeStyle = "red"; ctx.strokeText("描边:stroke+fill",10,300); ctx.fillStyle = "green"; ctx.fillText("描边:stroke+fill",10,300); //2.实心+空心 ctx.fillStyle = "green"; ctx.fillText("描边:fill+stroke",10,400); ctx.strokeStyle = "red"; ctx.strokeText("描边:fill+stroke",10,400); //2种描边效果的区分:简要来说就是:实心与空心谁后写,谁的效果更大! </script>

 

转载于:https://www.cnblogs.com/hamsterPP/p/5260195.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值