【发布时间】:2014-04-13 08:26:13
【问题描述】:
我正在尝试在画布中绘制文本,但绘制的文本有锯齿,尤其是在 chrome 31.0.1650 中。
我试过-webkit-font-smoothing:antialiased,text-shadow,但一切都是徒劳的。
如何解决这个问题? 提前致谢。
这里是样式代码:
<style>
#my_canvas{
-webkit-font-smoothing: antialiased;
text-shadow: 1px 1px 1px rgba(0,0,0,0.004);
text-indent: -9999px;
}
</style>
正文中的代码:
<canvas id="my_canvas" height="300" width="2200"></canvas>
<script>
var canvas = document.getElementById("my_canvas");
var context = canvas.getContext("2d");
context.imageSmoothingEnabled =true;
context.fillStyle = "BLACK";
context.font = "bold 100px Arial";
context.fillText("A quick brown fox jumps over the lazy dOg", 50, 200);
</script>
【问题讨论】:
-
是的,Text 不是 canvas 的强项。您不显示代码,因此很难具体说明。确保不要双笔划或双填文本。大多数字体看起来填充得更好,但没有描边。
-
请分享您目前尝试过的代码。
-
谢谢你们!我添加了到目前为止完成的代码。我什至尝试了阴影和模糊效果,但它没有给出预期的结果。
-
@markE 我没有使用双填充文本或描边。我添加了代码,到目前为止已经完成。代码有什么问题吗?
-
@Ken 我已编辑帖子以分享到目前为止完成的代码。
标签: css html5-canvas font-smoothing