[英]HTML5: Canvas Context fillText/strokeText does not draw
I am following a tutorial from Dev.Opera about HTML5 Painting application and trying to improve it by adding a text tool that prompts user of what text they wanted to input after clicking on coordinate. 我正在关注Dev.Opera关于HTML5 绘图应用程序的教程,并尝试通过添加一个文本工具来改进它,该工具在单击坐标后提示用户输入他们想要输入的文本。
Eg User clicked on coordinate 100,200 , a prompt will ask what text they wanted to show and after user entered the text, it should draw it on canvas. 例如,用户点击坐标100,200,提示将询问他们想要显示的文本,用户输入文本后,应该在画布上绘制。
I knew my browser support canvas fillText and strokeText function, because when I load this web the text shows. 我知道我的浏览器支持canvas fillText和strokeText函数,因为当我加载这个web文本显示时。
On the tutorial I follow, Dev.Opera creates a temp canvas on the real canvas so that images (shapes and text) are supposedly drawn to temp canvas and then transferred to real canvas by img_update() method. 在我关注的教程中,Dev.Opera在真实画布上创建一个临时画布,以便将图像(形状和文本)绘制到临时画布,然后通过img_update()方法转移到真实画布。
// This function draws the #imageTemp canvas on top of #imageView,
// after which #imageTemp is cleared. This function is called each time when the
// user completes a drawing operation.
function img_update () {
contexto.drawImage(canvas, 0, 0);
context.clearRect(0, 0, canvas.width, canvas.height);
}
I tried to do fillText on context like this: 我尝试在上下文中执行fillText,如下所示:
context.fillText(textVar, x, y);
img_update();
and this does not draw the text, while: 并且这不会绘制文本,而:
contexto.fillText(textVar, x, y);
draws it perfectly. 把它画得很完美。 I had expand the program to draw circle, polyline, and fills and all of them works perfectly on the context without having to draw them at contexto.
我已经扩展了程序以绘制圆形,折线和填充,并且所有这些都在上下文中完美地工作,而不必在上下文中绘制它们。
How can I force the text to be drawn at context and then transfer it using img_update()? 如何强制在上下文中绘制文本然后使用img_update()传输它?
也许填充样式设置,以便您看不到文本?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.