How can I write text on a HTML5 canvas element?

前端 未结 8 1115
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 21:36

Is it possible to write text on HTML5 canvas?

8条回答
  •  醉话见心
    2020-11-28 22:25

    It is easy to write text to a canvas. Lets say that you canvas is declared like below.

    
      
       Your Internet Browser does not support HTML5 (Get a new Browser)
      
    
    

    This part of the code returns a variable into canvas which is a representation of your canvas in HTML.

      var c  = document.getElementById("YourCanvas");
    

    The following code returns the methods for drawing lines, text, fills to your canvas.

      var ctx = canvas.getContext("2d");
    
    
    

    There is a beginners guide out on Amazon for the kindle http://www.amazon.com/HTML5-Canvas-Guide-Beginners-ebook/dp/B00JSFVY9O/ref=sr_1_4?ie=UTF8&qid=1398113376&sr=8-4&keywords=html5+canvas+beginners that is well worth the money. I purchased it a couple of days ago and it showed me a lot of simple techniques that were very useful.

提交回复
热议问题