微信小程序canvas

3966关注11918浏览

将页面保存为图片 图片是透明没有内容(手机上为黑色)

页面如何保存为图片啊(我写的好像不行)?????


保存后是这样 没有内容 而且手机上是黑色的




js:


Page({

/**

  * 页面的初始数据

  */

data: {

},


/**

  * 生命周期函数--监听页面加载

  */

onLoad: function (options) {

var that = this;

var withs = 0;

var heights = 0;

//获取屏幕 宽高

wx.getSystemInfo({

success: function (res) {

withs = res.screenWidth;

heights = res.screenHeight -100;

that.setData({withs:withs,heights:heights})

}

})


//画布

const ctx = wx.createCanvasContext('share')

ctx.rect(0, 0, withs, heights-10)

ctx.stroke()

ctx.draw(false, function(){//回调

wx.canvasToTempFilePath({

canvasId: 'share',

success: (res) => {

that.setData({

shareTempFilePath: res.tempFilePath

})

}

})

})

},


//保存至相册

saveImage: function () {

var t = this.data.shareTempFilePath

if (!this.data.shareTempFilePath) {

wx.showModal({

title: '提示',

content: '图片绘制中,请稍后重试',

showCancel: false

})

}

wx.saveImageToPhotosAlbum({

filePath: this.data.shareTempFilePath,

success: (res) => {

console.log(res)

},

fail: (err) => {

console.log(err)

}

})

}

})


wxml:


<view class="container">

<canvas canvas-id='share' style='width:100vw;height:{{heights}}px;'><view>4534</view></canvas>

</view>

<view class='tips' bindtap='saveImage'>点击保存图片</view>





展开全部
收起
0回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部