简体   繁体   中英

writing text on canvas again and again using JavaScript

I am writing JavaScript. I have insert Image on canvas and with another function I have put text from text box to canvas image by button click. but now problem is this if i enter different text in textbox and click button again and again it over writes text again and again. I want previous text should clear and new text come on the Image. I do not want to clear Image. Anyone can help me please?

A few options

  1. Overlay the text in another element and just update that
  2. Clear and redraw the relevant portion of the canvas (requires you keep a history of all drawing commands)
  3. Convert to SVG

Canvas only holds the raster state of the drawing. It has no concept of order or sub-elements. The first is likely the easiest but hard to tell without knowing what you are doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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