小程序
小游戏
企业微信
微信支付
扫描小程序码分享
微信小程序画布生成图片在华为手机上黑屏
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
具体啥型号的手机,系统版本是多少;我有一台华为的设备,没有遇到过你这个问题,你可以提供下代码片段我们试试
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
具体啥型号的手机,系统版本是多少;我有一台华为的设备,没有遇到过你这个问题,你可以提供下代码片段我们试试
previewshow() {
var mbinfo = this.data.mbinfo;
this.setData({
textheight: 0,
textwidth:0,
maincanvwidth:mbinfo.width * 2,
maincanvheight:mbinfo.height * 2
})
var that = this;
if (!ctx) {
var tt = wx.createCanvasContext("myCanvas",this);
ctx = tt;
}
ctx.fillStyle = '#EBEBEB';
ctx.fillRect(0,0,mbinfo.width, mbinfo.height);
ctx.drawImage(
mbinfo.url,
0,
0,
mbinfo.width,
mbinfo.height
);
var canvasviewlist = this.data.canvasview;
if(canvasviewlist.length > 0){
ctx.draw(true);
}
if (this.data.canvasShow == false) {
wx.showLoading({
title: '生成中',
mask: true
});
var zbheight = wx.getStorageSync('zbheight');
for (let i = 0; i < canvasviewlist.length; i++) {
ctx.save()
var sjtop = canvasviewlist[i].top - this.data.rectheight;
var thiswidth = canvasviewlist[i].widthss;
var thisheight = canvasviewlist[i].heightss;
var leftbl = canvasviewlist[i].left / zbheight;
var sjtop = sjtop / zbheight;
if (canvasviewlist[i].rotate != 0) {
// var centerpoitx = canvasviewlist[i].left + canvasviewlist[i].width / 2;
// var centerpoity = canvasviewlist[i].top + canvasviewlist[i].height / 2;
// var rotatenumber = canvasviewlist[i].rotate * Math.PI / 180;
// ctx.translate(centerpoitx, centerpoity);
// ctx.rotate(rotatenumber);
// ctx.translate(-centerpoitx, -centerpoity);
var centerpoitx = leftbl + thiswidth / 2;
var centerpoity = sjtop + thisheight / 2;
var rotatenumber = canvasviewlist[i].rotate * Math.PI / 180;
ctx.translate(centerpoitx, centerpoity);
ctx.rotate(rotatenumber);
ctx.translate(-centerpoitx, -centerpoity);
}
console.log(thiswidth);
ctx.drawImage(
canvasviewlist[i].url,
leftbl,
sjtop,
thiswidth,
thisheight
);
ctx.restore()
}
setTimeout(() => {
ctx.draw(true, () => {
wx.canvasToTempFilePath({
canvasId: 'myCanvas',
fileType: "jpg",
quality:0.8,
width:mbinfo.width,
height:mbinfo.height,
destWidth:mbinfo.width,
destHeight:mbinfo.height,
success: function(res) {
// 在H5平台下,tempFilePath 为 base64
wx.setStorageSync('this_f_thumb', res.tempFilePath);
that.uploadimg(res.tempFilePath);
},
fail(res) {
wx.showLoading({
title: '生成失败',
mask: true
});
}
})
wx.hideLoading();
ctx.draw();
});
}, 2000)
} else {
ctx.draw();
}
},