const ctx = wx.createCanvasContext(‘myCanvas’);
var that = this;
wx.chooseImage({
count: 1, // 默认9
sizeType: [‘original’, ‘compressed’], // 可以指定是原图还是压缩图,默认二者都有
sourceType: [‘album’, ‘camera’], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
that.setData({
isMod: false,
isCut: true,
bgColor: “black”,
tempFilePaths:res.tempFilePaths[0]
})
var tempFilePaths = res.tempFilePaths[0];
wx.getSystemInfo({
success: function (res) {
that.setData({
width: res.windowWidth,
height: res.windowHeight,
lastX: res.windowWidth * 0.23,
lastY: 0
})
}
})
ctx.save()
ctx.beginPath()
ctx.setFillStyle(‘white’);
ctx.fillRect(that.data.width * 0.1, 30, that.data.width * 0.8, that.data.height * 0.3);
ctx.clip();
ctx.drawImage(that.data.tempFilePaths, that.data.width * 0.23, 0, 200, 300)
ctx.restore()
ctx.draw();
}
})