Bug:
用canvasPutImageData在隐藏的canvas上作图后,导出图片失败
画布隐藏,然后用canvasPutImageData作图,然后导出图片是到不出来的,把画布Hidden属性去掉就能导出了
这个应该和draw一样在隐藏的画布上也能作图
关键代码
wx.downloadFile({
url: ‘https://cwrjl.com/api/GetInternetPic?imgPath=’ + temp.url, //仅为示例,并非真实的资源
success: function (res) {
fontctx.drawImage(res.tempFilePath, 0, 0, temp.width, temp.height)
fontctx.draw(false,function()
{
wx.canvasGetImageData({
canvasId: ‘fontchangeCanvas’,
x: 0,
y: 0,
width: temp.width,
height: temp.height,
success(res) {
for(let i=0;i<res.data.length;i++)
{
if ((i + 1) % 4 == 0 && res.data[i]!=0)
{res.data[i-3]=255;
}
}
let data=res.data;
console.log(data);
wx.canvasPutImageData({
canvasId: ‘fontchangeCanvas’,
x: 0,
y: 0,
width: temp.width,
data: data,
success(res) {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: temp.width,
height: temp.height,
canvasId: ‘fontchangeCanvas’,
success: function (res) {
console.log(res.tempFilePath)
let alertstring = ‘viewlist[1].url’
that.setData({
[alertstring]: res.tempFilePath
});
}
})
}
})
}
})
})