How to draw in & lt;canvas/>
This article mainly explains "how to draw in the middle". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to draw in the middle".
Draw a picture on Canvas
All drawings in must be done in JavaScript:
WXML: (we will use this WXML as a template in the following example if there is no special declaration, so we will not repeat it.)
JS: (we will put JS in onLoad in the next example)
Const ctx = wx.createCanvasContext ('myCanvas') ctx.setFillStyle (' red') ctx.fillRect (10,10,150,75) ctx.draw () first step: create a Canvas drawing context
First, we need to create a Canvas drawing context CanvasContext.
CanvasContext is an object built into Mini Program, and there are some drawing methods:
Const ctx = wx.createCanvasContext ('myCanvas') step 2: describe the drawing using the Canvas drawing context
Next, let's describe what to draw in Canvas.
Set the fill color of the drawing context to red:
Ctx.setFillStyle ('red')
Use the fillRect (x, y, width, height) method to draw a rectangle and fill it with the red you just set:
Ctx.fillRect (10,10,150,75) step 3: draw
Tell the component that you want to draw the description you just gave:
Ctx.draw () Thank you for your reading, the above is the content of "how to draw in". After the study of this article, I believe you have a deeper understanding of the problem of how to draw in, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!