Securityerror: Load An Image In Canvas, Modify It And Create Dataurl
I'm attempting to use HTML5 to bring in an image file, draw it to the canvas, do some manipulation of it, then return the dataURL so that I can reference this newly generated imag
Solution 1:
Cross origin needs to be set on the server hosting the image making it a CORS enabled image if you want to do any sort of image modification.
If this is not set on the server side the only other option is to download the image via a server side proxy on the same domain as your script. As long as the image is coming from the same domain you'll be able to modify it.
Solution 2:
My code does not have the security error:
<pre>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title></title></head><scriptsrc="Scripts/jquery-2.1.0.min.js"></script><scripttype="text/javascript">functionWindowsLoad()
{
var c = document.getElementById("myCanvas");
var cxt = c.getContext("2d");
var img = newImage();
img.src = "http://www.google.com/images/srpr/logo3w.png";
//img.src = 'image/placemark.png';
img.onload = function () {
cxt.drawImage(img, 0, 0);
}
console.log(c.toDataURL());
}
</script><bodyonload="WindowsLoad();"><formid="form1"runat="server"><div><canvasid="myCanvas"></canvas></div></form></body></html></pre>
Post a Comment for "Securityerror: Load An Image In Canvas, Modify It And Create Dataurl"