1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| const context = wx.createCanvasContext('screenCanvas'); const imageUrl="/static/images/family.jpg" const imageUrl1="/static/images/erCode.png" context.drawImage(imageUrl, 0, 0, canvasWidth.value,canvasHeight.value*0.6) context.beginPath(); context.moveTo(0, canvasHeight.value * 0.5); context.arcTo(canvasWidth.value / 4, canvasHeight.value * 0.6, canvasWidth.value * 0.5, canvasHeight.value * 0.6,canvasHeight.value-canvasHeight.value * 0.6 ); context.arcTo(canvasWidth.value * 0.75, canvasHeight.value * 0.6, canvasWidth.value, canvasHeight.value * 0.5,canvasHeight.value-canvasHeight.value * 0.6 ); context.lineTo(canvasWidth.value, canvasHeight.value * 0.5); context.lineTo(canvasWidth.value, canvasHeight.value); context.lineTo(0, canvasHeight.value); context.lineTo(0, canvasHeight.value*0.5); context.fillStyle = "rgb(255, 128, 0)"; context.fill(); context.closePath() const a=canvasWidth.value/710 const b=canvasHeight.value/674 const scX=a>b?b:a const width=710*scX/2 const height=674*scX/2 context.drawImage(imageUrl1,0, 0,710,674, canvasWidth.value / 2 -width/2, canvasHeight.value*0.65-height/2, width, height); context.closePath(); context.beginPath(); context.fillStyle = "rgb(255, 85, 0)"; context.font='italic bold 33px Microsoft Yahei' context.fillText('速达·陪诊', canvasWidth.value / 10, canvasHeight.value/2.6) context.font='italic bold 30px Microsoft Yahei' context.fillText('快速·必达', canvasWidth.value / 2, canvasHeight.value/2.2) context.closePath(); context.fillStyle = "rgb(255, 255, 255)"; context.font='18rpx Microsoft Yahei' const len=btText1.value.length/2 context.fillText(btText1.value, canvasWidth.value /2-20*len, canvasHeight.value-50) context.font="18rpx Microsoft Yahei" context.fillText(btText2.value, canvasWidth.value / 2-20*len, canvasHeight.value-25) context.draw(true) context.draw(true, function() { wx.canvasToTempFilePath({ canvasId: 'screenCanvas', destWidth: canvasWidth.value, destHeight: canvasHeight.value, success: function (res) { tempFilePath.value = res.tempFilePath; wx.showToast({ title: '生成成功', icon: 'success', duration: 2000 }) }, fail: function (res) { wx.showToast({ title: '生成失败', icon: 'none', duration: 2000 }) } }) }); }
|