这下舒服了
这下舒服了
  • 发布:2022-01-18 15:28
  • 更新:2022-01-18 15:28
  • 阅读:1290

canvas签名插件如何设置透明背景?

分类:uni-app

如题.

代码部分使用了签名组件: 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背景改变为黑色,
保存的图片也是黑色背景. 求大佬指教一下...

2022-01-18 15:28 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复