canvas.toDataURL导致实心黑色图像? [英] canvas.toDataURL results in solid black image?
本文介绍了canvas.toDataURL导致实心黑色图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个canvas元素,其中有一些涂鸦。
I have a canvas element with some doodling in it.
我使用下面的将canvas转换为jpeg:
I am using the following to convert the canvas to a jpeg:
var data = canvas.toDataURL( "image/jpeg", 0.5 );
var img = new Image();
img.src = data;
$( "body" ).append( img );
但是我不是我的涂鸦,而是一个黑色的jpeg。
However instead of my doodle, I get a solid black jpeg.
任何人都可以告诉我我做错了什么?
Can anyone tell me what I'm doing wrong?
谢谢!
推荐答案
这是因为JPEG不支持透明背景。如果你想要支持使用png(默认扩展),否则你可以设置非透明填充颜色到画布使用。 fillStyle
和。 fillRect
Thats happening because the JPEG does not support a transparent background.. if you want that to be supported use png (the default extension) else you can set a non transparent fill color to the canvas using .fillStyle
and .fillRect
这篇关于canvas.toDataURL导致实心黑色图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文