Javascript getImageData for canvas html5
我已经把头发扯下来了!我得到了这个工作,认为“我可以承担不保存这个版本的费用”,然后我..打破了“构建”。
myImageData = context.getImageData(0, 0, canvas.width, canvas.height); 行似乎打破了这一点,因为警报会在之前起作用,但在之后不起作用。
图像本身正在加载。
欢迎提出任何建议 ^_^ 我已无计可施,很快就会摆脱 RSI 的困扰。
var myImageData;
var image_var = new Image();
image_var.onload = function () {
canvas.width = image_var.width;
canvas.height = image_var.height;
context.drawImage(image_var, 0, 0, image_var.width, image_var.height);
myImageData = context.getImageData(0, 0, canvas.width, canvas.height);
alert('');
}
image_var.src = "example1.jpeg";
I've tearing my hair out! I got this working, thought 'i can afford not to save a version of this', then i .. broke the 'build'.
The line myImageData = context.getImageData(0, 0, canvas.width, canvas.height);
seems to breaking this, as an alert will work before, but not after it.
The image itself is loading.
Any and all suggestions welcomed ^_^ I'm at tether's end, and going to get RSI from kicking myself soon.
var myImageData;
var image_var = new Image();
image_var.onload = function () {
canvas.width = image_var.width;
canvas.height = image_var.height;
context.drawImage(image_var, 0, 0, image_var.width, image_var.height);
myImageData = context.getImageData(0, 0, canvas.width, canvas.height);
alert('');
}
image_var.src = "example1.jpeg";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将下面的代码添加到您的实际代码中,
firefox
允许您在本地工作,它实际上做了什么?
当脚本调用此函数时,如果签名有效或启用了代码库主体,则可以授予扩展权限。如果用户以前没有访问过此主体,则会出现一个对话框,询问用户是否要接受签名的代码。与 Communicator 4.x 不同,Mozilla 不显示详细的 Java 授权对话框,而是显示一个简单的对话框,询问主体是否可信。用户可以接受或拒绝,并允许浏览器记住他们的选择。如第二个示例所示,可能会同时请求两项权限,因此只出现一个对话框。
仅在请求功能的范围内授予权限。此范围包括请求函数调用的任何函数。当脚本离开请求函数时,特权不再适用。
您可以在此处阅读更多相关信息
这是一个演示
Add below piece of code to your actual code,
firefox
allows you to work locallywhat actually it does ?
When the script calls this function, if the signature is valid or codebase principal are enabled, expanded privileges can be granted. If a user has not accessed this principal before, a dialog asks the user if he wants to accept the signed code. Unlike Communicator 4.x, Mozilla does not display a detailed Java grant dialog, rather a simple dialog asking if the principal can be trusted. The user can accept or deny and allow their choice to be remembered by the browser. As shown in the second example, two privileges may be asked for at once, so only one dialog appears.
Privileges are granted only in the scope of the requesting function. This scope includes any functions called by the requesting function. When the script leaves the requesting function, privileges no longer apply.
You can read more about it here
Here's a demo
我找到了一个解决方案 - 问题是我试图读取本地文件(即在我的计算机上),这些文件没有与之关联的域名(显然本地 IP 不计算在内)在这种情况下)。为了保护在线内容用户的利益安全,W3C + 浏览器已规定 getImageData() 不适用于存储在 JavaScript 所属服务器外部的文件。
不幸的是,它将本地文件视为无域,因此显然存在安全限制。我正在寻找克服这个问题的方法(目前正在研究 HTML5 中的 appCache 和 websql,可能会也可能不会取得成果)。我希望我的网络应用程序的用户不必上传他们正在使用的材料(这样他们就可以离线工作,并且出于安全原因)。欢迎任何建议!
I found a solution - the problem was that I was attempting to read local files(ie, on my computer), which don't have a domain name associated with them (apparently local ip doesn't count in this instance). To protect the security of interests of people with online content, the W3C + browsers have made it so that getImageData() doesn't work on files stored outside of the server that's home to the javascript.
Unfortunately, it treats local files as domainless, and so the security restrictions apply, apparently. I'm looking around for ways to overcome this problem (looking at appCache and websql in HTML5 at the moment, may or may not bear fruit). I'd prefer for the user of my web app not to have to upload the material they're working with (so they can work offline, and for security reasons). Any suggestions welcome!