`
foquanlin
  • 浏览: 19169 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

html5 canvas 字符串

阅读更多

基础API:

 

字符串

 

       使用Context对象的fillText()方法能够在画布中绘制字符串。fillText()方法的原型如下:

 

void fillText(text, left,top, [maxWidth]);

 

       其四个参数的含义分为是:需绘制的字符串,绘制到画布中时左上角在画布中的横坐标及纵坐标,绘制的字符串的最大长度。其中最大长度maxWidth是可选 参数。另外,可以通过改变Context对象的font属性来调整字符串的字体以及大小,默认为”10px sans-serif”。

 

<!DOCTYPE HTML>
<html>
<body>
<canvas id="canvas" width="200"height="100">   
         <p>Your browserdoes not support the canvas element!</p>   
</canvas>   
    
<script type="text/javascript">   
window.onload = function() {   
         var canvas =document.getElementById("canvas");   
         var context2D =canvas.getContext("2d");   
           
         context2D.font ="30px Times New Roman";   
         context2D.fillText("HelloCanvas!", 10, 35);   
}   
</script>   
</body>
</html>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics