gpt4 book ai didi

javascript - 是否有等效于 SVG 的 Canvas toDataURL 方法?

转载 作者:技术小花猫 更新时间:2023-10-29 12:50:49 26 4
gpt4 key购买 nike

<分区>

我正在尝试将 svg 图像加载到 Canvas 中以进行像素操作我需要一个类似 toDataURLgetImageData 的 svg 方法

在 Chrome/Safari 上我可以尝试通过图像和 Canvas 来完成

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 :))

但是我遇到了安全错误。还有其他办法吗?

这是问题的现场演示 http://clstff.appspot.com/gist/462846 (可以查看源码)

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com