2

我正在寻找带有文本的画布圆圈,但是我希望画布背景颜色与圆圈中文本的颜色不同。我下面的代码对背景和文本使用相同的颜色..

<canvas id="circlecanvas" width="50" height="50"></canvas>
<script>
    var canvas = document.getElementById("circlecanvas");
    var context = canvas.getContext("2d");
    var centerX = canvas.width / 2;
    var centerY = canvas.height / 2;
    context.arc(centerX, centerY, 25, 0, Math.PI * 2, false);
    context.fillStyle ="#dbbd7a";
    context.fill()
    context.font = 'bold 20pt Calibri';
    context.textAlign = 'center';
    context.fillText('34', centerX, centerY);
</script>
4

1 回答 1

4

尝试这个:

context.arc(centerX, centerY, 25, 0, Math.PI * 2, false);
context.fillStyle ="#dbbd7a";
context.fill()
context.font = 'bold 20pt Calibri';
context.textAlign = 'center';

context.fillStyle ="#ff0000";  // <-- Text colour here
context.fillText('34', centerX, centerY);

所以,基本上,context.fillStyle为文本设置。

于 2013-01-29T15:58:45.400 回答