我试图将图片加载到画布上下文中,但是Image对象的onload函数不会触发:
var img_url = document.getElementById('img').src.split('?')[0]
console.log('img: '+img_url.substring(8))
canvas1 = document.getElementById("canvas1");
ctx1 = canvas1.getContext("2d");
LoadImageToCtx1();
function LoadImageToCtx1()
{
var base_image = new Image();
//base_image.setAttribute('crossOrigin', 'anonymous');
var path = serverip+'load?path=/'+img_url.substring(8)+"&"+(new Date().getTime())
console.log("LoadImageToCtx: "+path)
base_image.onload = function(){
console.log('load img!')
ctx1.drawImage(base_image,0,0);
}
base_image.src = path;//-->file// cut
}
我确实尝试过将随机数输入到路径中,src声明是在onload函数之后但仍然没有触发onload ...任何想法?