将选项中的背景设置为#ffffff后,我的画布的颜色为白色,可以,但是除画布图像以外的其余区域都是透明的,我该如何将该剩余区域也设置为一种颜色,例如白色?
您可以将backgroundColor
为null
以使其透明或使用任何颜色以使画布以背景色呈现
在这里,更改backgroundColor选项具有效果,但是将其更改为null会在画布中创建黑色背景,而CSS中没有黑色背景。
当将backgroundColor设置为null时,我也使画布呈现黑色背景
html2canvas(canvasDom, {
allowTaint: true,
useCORS: true,
backgroundColor: "rgba(0,0,0,0)",
removeContainer: true,
x: 0,
y: 0,
width: 374,
height: 722
})
allowTaint: true
和backgroundColor: "rgba(0,0,0,0)"
解决了问题
我认为allowTaint
在解决此问题方面没有任何帮助。 为了我
backgroundColor: 'rgba(0, 0, 0, 0)',
removeContainer: true,
设置是需要的。
最有用的评论
html2canvas(canvasDom, { allowTaint: true, useCORS: true, backgroundColor: "rgba(0,0,0,0)", removeContainer: true, x: 0, y: 0, width: 374, height: 722 })