有没有办法只更改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