在html2canvas中将透明颜色更改为白色 [英] change transparent color into white in html2canvas
问题描述
我使用javascript库 html2canvas 来保存我的项目表。它工作正常,但当我保存图像显示PNG透明背景颜色和背景颜色黑色的jpeg。
这是我做的:
I am using javascript library html2canvas to save the table of my project. It works fine but when I save the image it shows transparent background color for PNG and background color black for jpeg. Here is what I did:
<script>
window.onload = function(){
html2canvas(document.getElementById("tablePng"),{
onrendered: function(canvas){
var img = canvas.toDataURL('image/jpeg');
$('#saveTable').attr('href',img);
}
});
};
</script>
执行上述操作将保存图像,但背景颜色会变黑,更改 var img = canvas.toDataURL('image / png');
背景将是透明的。
在文档中添加背景:
Doing these above will save the images but the background colour will be black and when changing var img = canvas.toDataURL('image/png');
the background will be transparent.
And adding background as In documentation says:
<script>
window.onload = function(){
html2canvas(document.getElementById("tablePng"),{
background: "#fff",
onrendered: function(canvas){
var img = canvas.toDataURL('image/jpeg');
$('#saveTable').attr('href',img);
}
});
};
</script>
不会改变任何内容...给予透明。
will change nothing... give transparent.
那么,如何更改背景底色,以便保存的图像容易阅读?
So how do I change the background ground color so that the images saved will be readable easily?
推荐答案
background-color:#ffffff
到您的表格:)
希望这有助于
这篇关于在html2canvas中将透明颜色更改为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!