有沒有辦法只更改canvas上下文的字體大小而不必知道/寫入字體系列。在不知道字體系列的情況下更改Canvas的字體大小
var ctx = document.getElementById("canvas").getContext("2d");
ctx.font = '20px Arial'; //Need to speficy both size and family...
注:
ctx.fontSize = '12px'; //doesn't exist so won't work...
ctx.style.fontSize = '20 px' //doesn't exist so won't work...
//we are changing the ctx, not the canvas itself
其他說明:我可以這樣做:檢測其中「PX」是,刪除「PX」之前什麼是和我的字體大小替換它。但是如果可能的話,我希望比這更容易。
你正在做我在其他說明中提到過的事情: – RainingChain
@RainingChain我可能會失明,但你在哪裏顯示? – K3N
@RainingChain沒有辦法指定字體。 Canvas的字體是在CSS的短版本字體之後建立的。 – K3N