简体   繁体   English

HTML5 Javascript:将文本保存到画布上吗?

[英]HTML5 Javascript: Save text onto canvas?

If you take a look at what I've done so far it'll help explain what I'm after, as I'm terrible at explaining normally haha. 如果您看看我到目前为止所做的一切,将有助于解释我的追求,因为我通常无法解释哈哈。 http://logomakr.bugs3.com/ http://logomakr.bugs3.com/

On my drawing app I've implemented the ability to add text to the canvas, however, it's not recording/saving onto the canvas like the shapes are. 在我的绘图应用程序中,我已经实现了将文本添加到画布的功能,但是,它并没有像形状那样记录/保存到画布上。 When I've tried looking into it, it seems like HTML Canvas text tends to place over the canvas not on it. 当我尝试查看它时,似乎HTML Canvas文本倾向于放置在画布上而不是画布上。 I even copied a simple: 我什至复制了一个简单的:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.font="30px Arial";
ctx.fillText("Hello World",10,50);

to test it out, that displays on the canvas all fine and dandy but soon as you draw a shape it vanishes and even just pressing the save button the text isn't on the png? 要进行测试,它可以在画布上完美显示,但绘制形状后就消失了,甚至只是单击保存按钮,文本也就不在png上了?

Is there like an alternative or a way round it? 有没有其他选择或解决方法?

(Let me know if you need to see the code although I'm sure you's will be able to view source on website) (尽管我确定您可以在网站上查看源代码,但让我知道您是否需要查看代码)

Thank you in advance! 先感谢您!

For drawn shapes (rects, circles, lines) you're using the mouseup event to trigger saving the "tempCanvas" to the "realCanvas". 对于绘制的形状(矩形,圆形,直线),您正在使用mouseup事件触发将“ tempCanvas”保存到“ realCanvas”。

But for text, you're not saving the tempCanvas to the realCanvas at all. 但是对于文本,您根本就不会将tempCanvas保存到realCanvas。 Then when you clear the tempCanvas for additional drawings, the text is blown away. 然后,当您清除tempCanvas中的其他图形时,文本将被吹走。 Maybe you could add a [save text] button so the user can trigger saving text's tempCanvas to realCanvas. 也许您可以添加一个[save text]按钮,以便用户可以触发将文本的tempCanvas保存到realCanvas。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM