canvas.toDataURL 导致纯黑色图像? [英] canvas.toDataURL results in solid black image?
本文介绍了canvas.toDataURL 导致纯黑色图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个画布元素,里面有一些涂鸦.
I have a canvas element with some doodling in it.
我正在使用以下内容将画布转换为 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屋!
查看全文