2015-07-11 46 views
1

所以我想使這個畫布上有不同的類型上的文字,包括顏色。這裏我到目前爲止。我如何有文字的不同顏色在HTML畫布

<!DOCTYPE html> 
<html> 
<body> 

<canvas id="myCanvas" width="400" height="200" style=" border:1px solid #d3d3d3;"> 
Your browser does not support the HTML5 canvas tag.</canvas> 

<script> 
window.onload = function(){ 
    var canvas = document.getElementById("myCanvas"); 
    var context = canvas.getContext("2d"); 
    var imageObj = new Image(); 
    imageObj.onload = function(){ 
     context.drawImage(imageObj, 0, 0); 
     context.font = "40pt Calibri"; 
     context.fillText("My TEXT!", 50, 100); 
    }; 
    imageObj.src = "Assets/Background2.png"; 
}; 
</script> 
</body> 
</html> 
+0

你是什麼意思「文本類型」?字體?文字顏色,文字大小_and_字體?只需在'context.fillText'後面設置'context.font'就可以了。 – Xufox

+0

@Xufox謝謝你,我真的很新。如何更改文字顏色? –

+0

@AnomousPerson使用'context.fillStyle = [color]' –

回答

1

你只需要你想改變你的字體顏色,每次使用填充樣式方法:

context.fillStyle = 'red'; 
+1

和'context.font'爲字體和字體大小。 – Xufox

相關問題