生成canvas海报图,海报里透明底的小程序码会变黑色。测试版是正常的,只有在正式版才会
发布于 5 年前 作者 kangping 1577 次浏览 来自 官方Issues
const ctx = uni.createCanvasContext('myCanvas');
ctx.clearRect(0,0,that.canvasWidth,that.canvasHeight)
// 绘制海报
ctx.drawImage(posterinfo.path, 0, 0, posterinfo.width, posterinfo.height);
ctx.save();
// 绘制二维码
var codeWidth = 150;
var codeHeight = 150;
var codeX = that.canvasWidth - 25 - codeWidth; //二维码x坐标
var codeY = 25; //二维码y坐标
var arcR = codeWidth / 2;
ctx.beginPath();
ctx.arc(codeX + arcR, codeY + arcR, arcR, 0, 2 * Math.PI);
ctx.setFillStyle('rgba(255,255,255,0.6)');
ctx.fill();
ctx.drawImage(codeinfo.path, codeX, codeY, codeWidth, codeHeight);
console.log(posterinfo.path, codeinfo.path);
ctx.draw(false,()=>{
  uni.canvasToTempFilePath({
        canvasId:'myCanvas',
        x:0,
        y:0,
        width:that.canvasWidth,
	height:that.canvasHeigh,
	destWidth:that.canvasWidth,
	destHeight:that.canvasHeight,
	fileType:'jpg',
	success(res){
		that.canvasImg = res.tempFilePath
		console.log(res.tempFilePath)
		resolve(res.tempFilePath)
	},fail(err) {
		reject(err)
	}
  })
});

回到顶部