DWQA QuestionsCategory: ProgramAbout canvas, why bother to write so much code with JS to draw a picture? Isn't it good to directly use a picture
lizhigang asked 4 weeks ago

Canvas draws a simple picture with a lot of code. Why use canvas? Why not use a picture directly

8 Answers
Best Answer
manxisuo answered 4 weeks ago

If it’s a one-time drawing, of course.
What if the picture needs to be adjusted in the future? Draw another picture? If you use canvas, you can adjust the parameters.
What if you want to do animation, draw a lot of pictures and switch them regularly? If you use canvas, write a piece of code logic.
Another story:

Our former project team wanted to make a graphical display of the percentage effect. It is similar to a measuring cylinder filled with liquid, 0% empty and 100% full. So one of my colleagues asked the artists to draw a hundred pictures. Later, I used canvas to make only two pictures.

StinsonZhao replied 4 weeks ago

Story moving

Jing Wen replied 4 weeks ago

Heart pain artist

Code code animals answered 4 weeks ago

OK, so you can make this with pictures and control the mouse

10086 answered 4 weeks ago

Since something exists, it has the value of existence.
Canvas is a major feature of HTML5, and it must have its own requirements. Let me say one of my projects.
Main requirements of the project: image OCR recognition, which displays the results of image recognition in the front section. The result of recognition is the content in the image. The front section needs to mark each content with a red marking line. The front section gets the coordinates, and then what lines are drawn with? Use canvas. When the professionals view the results, they are very picky. They need to scale and move the image, and the wireframe also needs to scale and move accurately, and the magnification of the image does not lead to the magnification of the wireframe. That is to say, after the image is scaled, the wireframe needs to relocate the coordinates and draw new lines. No canvas, I can’t get so many images.
The use of canvas can be summarized as follows:

  1. It is often used for dynamic and special effect image display. There’s a sense of comics.
  2. Canvas can do 3D effects
  3. Canvas has the function of canvas, which can design online drawing
  4. The canvas is gorgeous…
ivanilla answered 4 weeks ago

Pictures are dead, gifs are semi alive but can’t interact with users. Canvas can interact with users, and it’s not as simple as drawing a picture, and it can achieve powerful graphic effects (including 3D). This is definitely not a picture can do.

aristotll answered 4 weeks ago