NS_ERROR_NOT_AVAILABLE:组件不可用 [英] NS_ERROR_NOT_AVAILABLE: Component is not available

查看:975
本文介绍了NS_ERROR_NOT_AVAILABLE:组件不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。我试图在画布上绘制图像。图像不是从HTML页面,而是在一个文件。这里是我使用的代码:

I have a problem. I am trying to draw an image onto a canvas. The image is not from the HTML page, but on a file. Here is the code i use:

var img = new Image();
img.src = "/images/logo.jpg";
this._canvas.drawImage(img, 300, 300);// this is line 14

现在,这里的问题。这似乎不工作在Firefox和IE10(我还没有在其他浏览器上测试)。在Firefox(21)我得到:

now, here's the problem. This does not seem to work on Firefox and IE10 (I haven't tested yet on other browsers). On Firefox (21) I get:

[19:09:02.976] NS_ERROR_NOT_AVAILABLE: Component is not available @ file:///D:/Watermellon/scripts/base-classes.js:14

并且在IE10我得到:

and on IE10 i get:

SCRIPT16389: Unspecified error. 
base-classes.js, line 14 character 13

文件及其目录是:

root/index.html  
root/scripts/base-classes.js  
root/images/logo.jpg 



现在,当我将img.src更改为URL(来自其他网站的图片)一切工作正常,图像绘制自己后一段时间(因为它是从url)。我做错了什么?

Now when I change the img.src to a URL (an image from another site) everything works fine, the image draws itself after a delay(for it's get from the url). What am I doing wrong?

推荐答案

我猜测的问题是,图像尚未加载,用它。试试这个:

I'm guessing the problem is that the image isn't loaded yet before you attempt to use it. Try this:

var img = new Image();
img.onload = function () {
    this._canvas.drawImage(img, 300, 300);// this is line 14
};
img.src = "images/logo.jpg";

src 属性设置之后绑定事件,因为缓存图片的加载事件立即触发(这是IE中的常见问题)。

The src property is set after binding the event because a cached image's load event fires immediately (which is a common problem in IE).

根据你的结构,图像的路径可能是 images / logo.jpg (删除第一个 /

And according to your structure, the path to the image would probably be images/logo.jpg (removing the first /)

这篇关于NS_ERROR_NOT_AVAILABLE:组件不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆