admin管理员组文章数量:1323335
Well not exactly. If I just draw (ex lines,rect...) and try to export the canvas as an image. It works fine. If I however use the canvas.drawImage(...)
function which places an image on the canvas. Then try to export it as an image, I get the following security error:
[16:05:05.326] uncaught exception: [Exception... "Security error" code: "1000" nsresult:
"0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location:
"http://127.0.0.1:8020/Blackboard/Models/BlackboardCanvas.js Line: 82"]
I was assuming that the canvas.drawImage
would take the raw pixel from the image and paste it onto the canvas, but I guess I was wrong. What can I do?
Well not exactly. If I just draw (ex lines,rect...) and try to export the canvas as an image. It works fine. If I however use the canvas.drawImage(...)
function which places an image on the canvas. Then try to export it as an image, I get the following security error:
[16:05:05.326] uncaught exception: [Exception... "Security error" code: "1000" nsresult:
"0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location:
"http://127.0.0.1:8020/Blackboard/Models/BlackboardCanvas.js Line: 82"]
I was assuming that the canvas.drawImage
would take the raw pixel from the image and paste it onto the canvas, but I guess I was wrong. What can I do?
- Can you give a portion of the code that causes the problem? – epascarello Commented Nov 14, 2011 at 21:12
-
2
Where does the image e from? If you're using
.drawImage
with a cross-domain image, then you'll be unable to use.getImageData
or.toDataURL
. – pimvdb Commented Nov 14, 2011 at 21:14 - Yea I think thats the problem, the cross-domain image. Any way around this? – dchhetri Commented Nov 14, 2011 at 21:33
2 Answers
Reset to default 6The behavior you describe is per the specification. Excerpted:
All
canvas
elements must start with their origin-clean set to true. The flag must be set to false if any of the following actions occur:
- The element's 2D context's
drawImage()
method is called with anHTMLImageElement
or anHTMLVideoElement
whose origin is not the same as that of theDocument
object that owns thecanvas
element.[...]
Whenever the
toDataURL()
method of acanvas
element whose origin-clean flag is set to false is called, the method must throw aSecurityError
exception.
The only way to circumvent this is to use a server-side technology to fetch the remote image for you and re-serve it from your same domain.
Are you waiting for the image to fully load before calling canvas.drawImage
?
var img = new Image();
img.onload = function(){
canvas.drawImage(img,0,0);
//do whatever else here
};
img.src = 'foo.jpg';
本文标签: javascriptGet security error when saving canvas object into an imageStack Overflow
版权声明:本文标题:javascript - Get security error when saving canvas object into an image - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742137508a2422435.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论