小程序的canvas怎么插入图片呀?
js代码
//定义全局canvas
let that = this
const ctx = wx.createCanvasContext('shareCanvas');
//绘制背景色
ctx.setFillStyle('#42d7c8')
ctx.fillRect(0, 0, 350, 700)
// 标题
ctx.setFillStyle('#333333')
ctx.setFontSize(20)
ctx.font = 'normal bold 15px sans-serif'
ctx.fillText('绿地新都会', 20, 20)
// 二维码
// 填充一个白色矩形
ctx.setFillStyle('white')
ctx.setShadow(0, 5, 16, 'rgba(185,185,185,0.5)');// 设置阴影
ctx.fillRect(17, 140, 280, 200)
wx.downloadFile({
url: 'https://file-skg.skg.com/skg.com/20210113/e0abb00dae6f4e0782b002f0831662e6.jpg',
success: res =>{
console.log("Res",res.tempFilePath)
ctx.drawImage(res.tempFilePath,10,10,150,150)
}
})
ctx.draw(); //实例化完成
// wxml 代码
<view class="container">
<canvas canvas-id="shareCanvas" class='canvas-style'>
</canvas>
<view class="linkcopy">
<text>分享链接</text>
<text bindtap="uploads">保存图片</text>
</view>
</view>