<view wx:if="{{show==true}}" >
<canvas style=“width:100%;height:{{windowHeight}}px;” canvas-id=“myCanvas”></canvas>
</view>
save: function () {
let that = this;
wx.showLoading({
title: ‘正在生成’,
mask: ‘true’
})
that.setData({
show: true
})
that.drawimage(that.data.windowWidth, that.data.windowHeight)
setTimeout(() => {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: that.data.windowWidth,
height: that.data.windowHeight,
canvasId: ‘myCanvas’,
success: function (res) {
wx.hideLoading()
console.log(res.tempFilePath)
that.setData({
show:false
})
wx.previewImage({
urls: [res.tempFilePath],
})
}
})
},3000)
},
drawimage: function (width,height){
const ctx = wx.createCanvasContext(‘myCanvas’)
ctx.drawImage(’…/…/static/images/2.jpg’, 0, 0, width, height)
ctx.draw()
}
有一段黑