首页 > 代码库 > 解决图片跨域问题

解决图片跨域问题

var imgs = new Image();
imgs.crossOrigin = "Anonymous"; //注意存放顺序
imgs.src = "http://192.168.0.107/ZHCX/CGZSIMG/1.jpg";
imgs.onload = function () {
var canvas = document.createElement(‘canvas‘);
canvas.width = imgs.width;
canvas.height = imgs.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(imgs, 0, 0, imgs.width, imgs.height);
var img1 = new Image();
img1.src = http://www.mamicode.com/canvas.toDataURL("image/png");
alert("s")
}

imgs.onerror = function () {
alert("error")
}

解决图片跨域问题