交叉原点数据污染的画布 [英] Canvas tainted by cross-origin data

查看:249
本文介绍了交叉原点数据污染的画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从第三方网站加载动画jpeg,我可以信任。我试图 getImageData()但浏览器(Chrome 23.0)抱怨:

I'm loading a motion jpeg from third-party site, which I can trust. I'm trying to getImageData() but the browser (Chrome 23.0) complains that:

Unable to get image data from canvas because the canvas has been tainted by
cross-origin data.

在SO上有一些类似的问题,但他们使用本地文件,媒体。

There are some similar questions on SO, but they are using local file and I'm using third party media. My script runs on a shared server and I don't own the remote server.

我尝试了 img.crossOrigin ='Anonymous' img.crossOrigin =''(请参阅此帖子在Chromium博客上关于CORS ),但它没有帮助。关于如何在一个画布上的跨原始数据我可以 getImageData 的任何想法?谢谢!

I tried img.crossOrigin = 'Anonymous' or img.crossOrigin = '' (see this post on the Chromium blog about CORS), but it didn't help. Any idea on how can I getImageData on a canvas with cross-origin data? Thanks!

推荐答案

crossOrigin标志一旦被污染就无法复位,但如果你知道图片是什么将其转换为数据网址,请参阅绘制图像一个到画布的数据URL

You cannot reset the crossOrigin flag once it is tainted, but if you know before hand what the image is you can convert it to a data url, see Drawing an image from a data URL to a canvas

但是不能,不能也不应该从不支持CORS的外部源使用getImageData()

But no, you cannot and should not be using getImageData() from external sources that don't support CORS

这篇关于交叉原点数据污染的画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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