ImageCropper.prototype.getCroppedImageData = function(width, height, mime)
{
var output = document.createElement("canvas");
output.width = width || this.cropWidth;
output.height = height || this.cropHeight;
output.getContext("2d").drawImage(this.imageCanvas, this.cropLeft, this.cropTop, this.cropViewWidth, this.cropViewHeight, 0, 0, output.width, output.height);
var r = output.toDataURL(mime || "image/jpeg");
{
var output = document.createElement("canvas");
output.width = width || this.cropWidth;
output.height = height || this.cropHeight;
output.getContext("2d").drawImage(this.imageCanvas, this.cropLeft, this.cropTop, this.cropViewWidth, this.cropViewHeight, 0, 0, output.width, output.height);
var r = output.toDataURL(mime || "image/jpeg");
return r;
注意toDataURL在转换图片时候有同域要求,若非同域图片,就会出现SecurityError: The operation is insecure.
错误。
SecurityError: The operation is insecure.
解决方法:在跨域的服务器上header设置为允许跨域请求
access-control-allow-origin: * access-control-allow-credentials: true
例如:在jsp页面加上response.setHeader("Access-Control-Allow-Origin", "*");时,