Javascript getImageData for canvas html5

发布于 2024-10-01 06:05:18 字数 618 浏览 3 评论 0原文

我已经把头发扯下来了!我得到了这个工作,认为“我可以承担不保存这个版本的费用”,然后我..打破了“构建”。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

め可乐爱微笑 2024-10-08 06:05:18

将下面的代码添加到您的实际代码中,firefox 允许您在本地工作,

netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");

它实际上做了什么?

当脚本调用此函数时,如果签名有效或启用了代码库主体,则可以授予扩展权限。如果用户以前没有访问过此主体,则会出现一个对话框,询问用户是否要接受签名的代码。与 Communicator 4.x 不同,Mozilla 不显示详细的 Java 授权对话框,而是显示一个简单的对话框,询问主体是否可信。用户可以接受或拒绝,并允许浏览器记住他们的选择。如第二个示例所示,可能会同时请求两项权限,因此只出现一个对话框。

仅在请求功能的范围内授予权限。此范围包括请求函数调用的任何函数。当脚本离开请求函数时,特权不再适用。

您可以在此处阅读更多相关信息

这是一个演示 alt text

Add below piece of code to your actual code, firefox allows you to work locally

netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");

what 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 alt text

梦中的蝴蝶 2024-10-08 06:05:18

我找到了一个解决方案 - 问题是我试图读取本地文件(即在我的计算机上),这些文件没有与之关联的域名(显然本地 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文