火狐SVG画布的drawImage错误 [英] firefox svg canvas drawImage error
本文介绍了火狐SVG画布的drawImage错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想一个外部SVG图标转换为base64。这是工作在Firefox中,除了所有的浏览器将抛出一个错误NS_ERROR_NOT_AVAILABLE。
I am trying to convert a external svg icon to base64. It is working in all browsers except Firefox which throws an error "NS_ERROR_NOT_AVAILABLE".
var img = new Image();
img.src = "icon.svg";
img.onload = function() {
var canvas = document.createElement("canvas");
canvas.width = this.width;
canvas.height = this.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(this, 0, 0);
var dataURL = canvas.toDataURL("image/png");
return dataURL;
};
谁能帮我在这吗?先谢谢了。
can anyone help me on this please ? Thanks in advance.
推荐答案
Firefox不支持绘制SVG图像以帆布,除非SVG文件的宽度/高度的根属性< SVG>
元素以及宽/高属性不是百分比。这是一个长期的错误。
Firefox does not support drawing SVG images to canvas unless the svg file has width/height attributes on the root <svg>
element and those width/height attributes are not percentages. This is a longstanding bug.
您将需要编辑icon.svg文件,使其符合上述标准。
You will need to edit the icon.svg file so it meets the above criteria.
这篇关于火狐SVG画布的drawImage错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文