HTML5 画布文本编辑

2022-01-17 00:00:00 javascript html html5-canvas

我在 HTML5 画布中使用 fillText(); 填充了一个文本如何使其可编辑并将值读入变量?文本必须在画布内,因为它会写在一些复杂的多边形内.

解决方案

无法从画布中获取文本.您需要做的是在使用 fillText(); 并渲染画布之前将文本保存在变量中.当你想编辑画布中的文本时,你必须重新绘制画布,当你想用 fillText(); 渲染编辑的文本时,你必须再次从变量中读取文本..p>

I have a text filled in HTML5 canvas using fillText(); How to make it editable and read the value into a variable? The text must be inside canvas, as it will be written inside some complex polygon shape.

解决方案

You can not get the text from the canvas. What you need to do is to keep the text in a variable before you use fillText(); and render the canvas. When you want to edit the text in the canvas, you have to paint the canvas again, and read the text from the variable again when you want to render the edited text with fillText();.

相关文章