代码:
drawChar: function(oneChar, x, y) {
if (canvas.getContext) {
var g2d = canvas.getContext("2d"); //2d用引用括起来
}
if (!context) {
return;
}
drawText = String.fromCharCode(oneChar);
g2d.save();
g2d.beginPath();
g2d.moveTo(100, 100);
g2d.lineTo(800, 800);
// 设置画笔的颜色和大小
g2d.fillStyle = "red"; // 填充颜色为红色
g2d.strokeStyle = "blue"; // 画笔的颜色
g2d.lineWidth = 5; // 指定描边线的宽度
// 写字
g2d.font = "28px 宋体";
g2d.fillText(drawText, x, y);
g2d.closePath();
g2d.stroke();
g2d.restore();
}