如题.
代码部分使用了签名组件: https://ext.dcloud.net.cn/plugin?id=5768
注释中标名了, 设置canvas背景色或不设置时导出为透明, 代码如下
/* 将canvas背景设置为 白底,不设置 导出的canvas的背景为透明 */
this.setCanvasBg('#fff');
//设置canvas背景色 不设置 导出的canvas的背景为透明
//@params:字符串 color
setCanvasBg(color) {
/* 将canvas背景设置为 白底,不设置 导出的canvas的背景为透明 */
//rect() 参数说明 矩形路径左上角的横坐标,左上角的纵坐标, 矩形路径的宽度, 矩形路径的高度
//这里是 canvasHeight - 4 是因为下边盖住边框了,所以手动减了写
this.ctx.rect(0, 0, this.canvasWidth, this.canvasHeight - 4);
//ctx.setFillStyle('red');
this.ctx.setFillStyle(color);
this.ctx.fill(); //设置填充
this.ctx.draw(); //开画
},
在实际使用中, 注释了该部分, 或者注释 this.ctx.setFillStyle(color); 行后都会将canvas背景改变为黑色,
保存的图片也是黑色背景. 求大佬指教一下...
0 个回复