我试图加载到画布像素处理我需要一种方法像SVG图像toDataURL或getImageData对SVG
在Chrome/Safari上,我可以尝试通过图像和画布
var img = new Image()
img.onload = function(){
ctx.drawImage(img,0,0) //this correctly draws the svg image to the canvas! however...
var dataURL = canvas.toDataURL(); //SECURITY_ERR: DOM Exception 18
var data = ctx.getImageData(0,0,img.width, img.height).data //also SECURITY_ERR: DOM Exception 18
}
img.src = "image.svg" //that is an svg file. (same domain as html file :))
Run Code Online (Sandbox Code Playgroud)
但是我遇到了安全错误.还有其他方法吗?
这是一个问题的现场演示http://clstff.appspot.com/gist/462846(你可以查看源代码)
文本以外的 SVG 形状受shape-rendering可以设置为crispEdges值的属性的影响(https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/shape-rendering)。这个值似乎关闭了抗锯齿。
但文本仅受text-rendering. 但是,这不提供crispEdges值(https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-rendering)。为什么?有没有另一种方法来获得非抗锯齿?