# CanvasContext.drawImage(string imageResource, number sx, number His number sWidth, number sHeight, number dx, number Two number dWidth, number dHeight)

with Promise style call: Not supported

Mini Program plugin: Support

Draw Image to Canvas

# parameter

# string imageResource

The picture resource you want to draw a network picture is created through the GetImageInfo / downloadFile Download first)

# number sx

The upper-left corner of the imageResource rectangle (crop) selection box that needs to be drawn to the canvas x coordinate

# number His

The upper-left corner of the imageResource rectangle (crop) selection box that needs to be drawn to the canvas and coordinate

# number sWidth

Width of the selection box for the rectangle (crop) of the imageResource to be drawn to the canvas

# number sHeight

Height of the ImageResource rectangle (crop) selection box that needs to be drawn to the canvas

# number dx

ImageResource at the top left of the target canvas on x Axis position

# number Two

ImageResource at the top left of the target canvas on and Axis position

# number dWidth

Draws the width of the imageResource on the target canvas, allowing scaling of the drawn image Resource

# number dHeight

The height of the imageResource drawn on the target canvas, allowing the drawn imageReource to be scaled

# sample code

There are three versions:

  • drawImage(imageResource, dx, Two)
  • drawImage(imageResource, dx, Two dWidth, dHeight)
  • drawImage(imageResource, sx, His sWidth, sHeight, dx, Two dWidth, dHeight) from 1.9.0 Rise support
const ctx = wx.createCanvasContext('myCanvas')

wx.chooseImage({
  success: function(res){
    ctx.drawImage(res.tempFilePaths[0], 0, 0, 150, 100)
    ctx.draw()
  }
})