获取本地手机的屏幕宽高(宽高需要按照自己实际需求计算)
toCanvas() {
let that = this
wx.getSystemInfo({
success: function(res) {
console.log(res);
console.log(res.windowWidth / 750)
let company = res.windowWidth / 750
that.setData({
company:company
})
}
})
let windowWidth = wx.getSystemInfoSync().windowWidth;
let windowHeight = wx.getSystemInfoSync().windowHeight-90;
this.setData({
windowWidth:windowWidth,
windowHeight:windowHeight,
})
this.canvasFunction()
},
画canvas海报(设置按照自己的需求)
<view class="canvasHe">
<canvas canvas-id="myCanvas" style='width:100%;height:{
{
windowHeight}}px;' ></canvas>
</view>
wxss
.canvasHe{
width: 750rpx;
/* height: 510px; */
padding: 0rpx 15rpx;
box-sizing: border-box;
position: relative;
}
canvasFunction(params) {
let windowWidth = this.data.windowWidth-15;
let windowHeight = this.data.windowHeight;
let company = this.data.company;
let name=this.data.name;
let phone = this.data.phone;
let ewcode = this.data.ewcode;
let ewcodeW = this.data.ewcodeW;
let ewcodeH = this.data.ewcodeH;
const ctx = wx.createCanvasContext('myCanvas')
let bgPicturePath = "../../../static/canvasBeiJing.png";
ctx.drawImage(bgPicturePath, 0, 0, windowWidth