当Image的src url不可用时,在canvas上下文中处理调用drawImage的有效方法是什么?例如:
myImage.src = "ImageDoesNotExist";
canvasCtx.drawImage(myImage,0,0); // 0x80004005 - JavaScript runtime error: Unspecified error.
谢谢!
答案 0 :(得分:2)
除了image.onload
之外,这些场合还有image.onerror
var img = new Image();
img.onload = function(){
context.drawImage(img,0,0);
};
img.onerror = function(){
alert("Oops, bad stuff happened while loading this image.");
};
img.src = "ImageDoesNotExist";