微信小程序--canvas 画海报 转发好友 下载本地

获取本地手机的屏幕宽高(宽高需要按照自己实际需求计算)
  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; //可使用窗口宽度,单位px
    let windowHeight = wx.getSystemInfoSync().windowHeight-90; // 可使用窗口高度,单位px
    // console.log('windowWidth',windowWidth);
    // console.log('windowHeight',windowHeight);
    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) {
   
    // 创建Canvas绘图上下文对象CanvasContext
    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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值