admin管理员组文章数量:1310156
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>
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?
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>
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?
Share Improve this question edited May 27, 2014 at 14:30 Etheryte 25.3k12 gold badges76 silver badges120 bronze badges asked May 27, 2014 at 13:58 Bhim Prasad AleBhim Prasad Ale 5232 gold badges8 silver badges31 bronze badges 4- What kind of background color has your table element in the DOM? According to the documentation background sets the "Canvas background color, if none is specified in DOM. Set undefined for transparent". – nietonfir Commented May 27, 2014 at 14:00
- @nietonfir its while. I am using bootstrap table.<table id="tablePng" class="table" align="center" > – Bhim Prasad Ale Commented May 27, 2014 at 14:06
-
And what happens if you don't call the function
onload()
but manually instead? – nietonfir Commented May 27, 2014 at 14:10 - @nietonfir it won't work. Actually I made a link and when click on that link the download option will appear. When tried using manually I have to make another link to save a image. – Bhim Prasad Ale Commented May 27, 2014 at 14:14
1 Answer
Reset to default 6simply add css background-color:#ffffff
to your table :)
hope this helps
本文标签: javascriptchange transparent color into white in html2canvasStack Overflow
版权声明:本文标题:javascript - change transparent color into white in html2canvas - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741850278a2401025.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论