微信小程序canvas水印

const app = getApp()
Page({
  data: {
  },
  onLoad: function (e) {
  	wx.setNavigationBarTitle({
      title: "神符"
    })

    var ctx = wx.createCanvasContext('shenfu')
    ctx.drawImage("/images/"+app.globalData.cav_type+".jpg", 0, 0, 600, 1145)
    ctx.setTextAlign('center')    // 文字居中
    ctx.setFillStyle('#a00b0f')  // 文字颜色:黑色
    ctx.font="normal normal normal 20px KaiTi";
    ctx.fillText("ID:"+app.globalData.cav_name+"  所在大区:"+app.globalData.cav_daqu, 600/2, 1050)
    ctx.stroke()

    ctx.draw(false,function(){
        //回调方法
        wx.canvasToTempFilePath({
          x: 0,
          y: 0,
          width: 600,
          height: 1145,
          destWidth: 600,
          destHeight: 1145,
          canvasId: 'shenfu',
          success: function(res) {
            console.log(res.tempFilePath)
            
            wx.previewImage({
              current: '', // 当前显示图片的http链接
              urls: [res.tempFilePath], // 需要预览的图片http链接列表
              success: function(resa) {
                wx.saveImageToPhotosAlbum({
                  filePath: res.tempFilePath,
                  success(resb) {
                    wx.showModal({
                      title: '提示',
                      content: '神符已保存到相册中。',
                      showCancel:false,
                      success: function(res) {
                        if (res.confirm) {
                          console.log('用户点击确定')
                          wx.navigateTo({
                            url: '/pages/index/index'
                          })
                        } else if (res.cancel) {
                          console.log('用户点击取消')
                        }
                      }
                    })
                  }
                })

              }
            })
          } 
        })
    })

  },
  shengcheng:function(){
    wx.canvasToTempFilePath({
      x: 0,
      y: 0,
      width: 600,
      height: 1145,
      destWidth: 600,
      destHeight: 1145,
      canvasId: 'shenfu',
      success: function(res) {
        console.log(res.tempFilePath)
        wx.saveImageToPhotosAlbum({
            filePath: res.tempFilePath
        })

        //wx.previewImage({
        //  current: '', // 当前显示图片的http链接
        //  urls: [res.tempFilePath] // 需要预览的图片http链接列表
        //})
      } 
    })
  },
  goHome: function(){
    console.log('ss')
    wx.switchTab({
      url: '/pages/index/index'
    })
  }
})

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值