最近在做小程序海报功能,部分安卓机器出现诡异的现象
要么预览画布未完全渲染
有时候按钮也没展示
要么画布保存黑屏
//绘制知道展示保存按钮
ctx.drawImage('/assets/images/iconfont-home-active.png', 25 * scale, 95 * scale, 46 * scale, 46 * scale)
// ctx.draw(true)
ctx.draw(true,(()=>{
setTimeout(() => {
wx.hideLoading()
that.setData({
showSave: true,
})
}, 200);
})())
//保存这边的方法
let that = this
let ctx = wx.createCanvasContext('myCanvasPhone', this)
ctx.draw(true,(()=>{
// 判断绘制方法,判断手机类型
if (App.globalData.isIphone) {
setTimeout(() => {
that.getToTempFilePath()//保存图片
}, 200);
}
else{
setTimeout(() => {
that.getToTempFilePath()//保存图片
}, 500);
}
})())
执行函数名打错了
使用新的接口试下?https://developers.weixin.qq.com/miniprogram/dev/component/canvas.html
我按照文档资料使用新的接口 但是 输出打印是空内容 调试基础库 2.9.0
<canvas type="2d" id="myCanvas"></canvas>
const query = wx.createSelectorQuery()
query.select('#myCanvas')
.fields({ node: true, size: true })
.exec((res) => {
console.log(res)
const canvas = res[0].node
const ctx = canvas.getContext('2d')
const dpr = wx.getSystemInfoSync().pixelRatio
canvas.width = res[0].width * dpr
canvas.height = res[0].height * dpr
ctx.scale(dpr, dpr)
ctx.fillRect(0, 0, 100, 100)
})