我的代码就像
var url = "http://160.114.10.17:98/Upload/OEMLogo/ac3940d2-6e5c-45d5-9296-8387874c499a_Logo.png"
function getBase64FromImageUrl(url) {
var img = new Image();
img.setAttribute('crossOrigin', 'anonymous');
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width = this.width;
canvas.height = this.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(this, 0, 0);
var dataURL = canvas.toDataURL("image/png");
var url = dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
};
img.src = url;
}
当我尝试将图像转换为base64时,此错误将在consol中触发
来自原始“http://160.114.10.17:98/Upload/OEMLogo/ac3940d2-6e5c-45d5-9296-8387874c499a_Logo.png”的“http://localhost:8383”对图像的访问已被CORS策略阻止:请求的资源上没有“Access-Control-Allow-Origin”标头。因此,不允许原点“http://localhost:8383”访问。
请帮帮我。有谁有想法? 提前致谢