在 JavaScript 中,是否可以在 lines()
中使用任何类型的 fillStyle
?
这是我的代码:
var text = document.getElementById("text");
var first = text.getContext("2d");
first.font = "100px SimLLHP";
first.strokeStyle = "blue";
first.strokeText("T1",100,100);
var last = text.getContext("2d");
last.font = "100px SimLLHP";
last.strokeStyle = "blue";
last.strokeText("T2",110,180)
最佳答案
不,不是。 lines
和 fill
都有自己的属性和方法,以便在 HTML5 Canvas 上绘图。 lines
用于轮廓,例如轮廓或线条。以及实体形状的fill
。因此,fillStyle
仅用于填充,而 StrokeStyle
用于笔划。没有理由将它们混合在一起。
因此,如果您想填充文本,那么我们只需使用 fillStyle
和 fillText
即可。
var last = text.getContext("2d");
last.font = "100px SimLLHP";
last.fillStyle = "blue";
last.fillText("T2",110,180)
假设我们希望它被填充并有一个轮廓,那么我们首先进行填充
,然后描边
。
// I hope you don't mind me using "ctx", it's the most common.
var ctx = text.getContext("2d");
ctx.font = "100px SimLLHP";
ctx.fillStyle = "blue";
ctx.fillText("T2",10,100);
ctx.strokeStyle = "red";
ctx.strokeText("T2",10,100);
关于JavaScript fillStyle 可以与中风()一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24946312/