zoukankan      html  css  js  c++  java
  • stroke和fill顺序对绘图的影响

     用canvas绘制线条和填充,fill()和stroke()调用顺序直接影响绘制的结构

     先调用stroke在调用fill,绘制的效果看上去lineWidth只绘制出来一半,还以为是个大问题。

     1 <!DOCTYPE HTML>
     2 <html>
     3 <body>
     4 <canvas id="myCanvas" width=400 height=300>your browser does not support the canvas tag </canvas>
     5 <script type="text/javascript">
     6 var canvas=document.getElementById('myCanvas');
     7 var ctx=canvas.getContext('2d');
     8 ctx.lineWidth=10;
     9 ctx.fillStyle='#FF0000';
    10 ctx.strokeStyle='#000000';
    11 ctx.rect(5,5,80,100);
    12 ctx.stroke();
    13 ctx.fill();
    14 </script>
    15 </body>
    16 </html>

     先调用fill在调用stroke,直接就解决了上面绘制的lineWidth只绘制一半的问题!

     1 <!DOCTYPE HTML>
     2 <html>
     3 <body>
     4 <canvas id="myCanvas" width=400 height=300>your browser does not support the canvas tag </canvas>
     5 <script type="text/javascript">
     6 var canvas=document.getElementById('myCanvas');
     7 var ctx=canvas.getContext('2d');
     8 ctx.lineWidth=10;
     9 ctx.fillStyle='#FF0000';
    10 ctx.strokeStyle='#000000';
    11 ctx.rect(5,5,80,100);
    12 ctx.fill();
    13 ctx.stroke();
    14 </script>
    15 </body>
    16 </html>

     

  • 相关阅读:
    KVC
    MRC&ARC
    网络基础
    沙盒
    GCD深入了解
    iOS 架构模式MVVM
    iOS 源代码管理工具之SVN
    iOS给UIimage添加圆角的两种方式
    Objective-C 中,atomic原子性一定是安全的吗?
    iOS Block循环引用
  • 原文地址:https://www.cnblogs.com/fangsmile/p/7068607.html
Copyright © 2011-2022 走看看