<i id='CwGy6'><tr id='CwGy6'><dt id='CwGy6'><q id='CwGy6'><span id='CwGy6'><b id='CwGy6'><form id='CwGy6'><ins id='CwGy6'></ins><ul id='CwGy6'></ul><sub id='CwGy6'></sub></form><legend id='CwGy6'></legend><bdo id='CwGy6'><pre id='CwGy6'><center id='CwGy6'></center></pre></bdo></b><th id='CwGy6'></th></span></q></dt></tr></i><div id='CwGy6'><tfoot id='CwGy6'></tfoot><dl id='CwGy6'><fieldset id='CwGy6'></fieldset></dl></div>

  1. <small id='CwGy6'></small><noframes id='CwGy6'>

  2. <tfoot id='CwGy6'></tfoot>

    • <bdo id='CwGy6'></bdo><ul id='CwGy6'></ul>

    1. <legend id='CwGy6'><style id='CwGy6'><dir id='CwGy6'><q id='CwGy6'></q></dir></style></legend>

      如何修复 getImageData() 错误画布已被跨域数据污染?

      How to fix getImageData() error The canvas has been tainted by cross-origin data?(如何修复 getImageData() 错误画布已被跨域数据污染?)
        <bdo id='4hrnW'></bdo><ul id='4hrnW'></ul>

            <tfoot id='4hrnW'></tfoot>
            <i id='4hrnW'><tr id='4hrnW'><dt id='4hrnW'><q id='4hrnW'><span id='4hrnW'><b id='4hrnW'><form id='4hrnW'><ins id='4hrnW'></ins><ul id='4hrnW'></ul><sub id='4hrnW'></sub></form><legend id='4hrnW'></legend><bdo id='4hrnW'><pre id='4hrnW'><center id='4hrnW'></center></pre></bdo></b><th id='4hrnW'></th></span></q></dt></tr></i><div id='4hrnW'><tfoot id='4hrnW'></tfoot><dl id='4hrnW'><fieldset id='4hrnW'></fieldset></dl></div>
              <tbody id='4hrnW'></tbody>

              <small id='4hrnW'></small><noframes id='4hrnW'>

                <legend id='4hrnW'><style id='4hrnW'><dir id='4hrnW'><q id='4hrnW'></q></dir></style></legend>

              • 本文介绍了如何修复 getImageData() 错误画布已被跨域数据污染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我的代码在我的本地主机上运行良好,但在网站上却无法运行.

                My code is working very well on my localhost but it is not working on the site.

                我从控制台收到此错误,对于这一行 .getImageData(x,y,1,1).data:

                I got this error from the console, for this line .getImageData(x,y,1,1).data:

                Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data. 
                

                我的部分代码:

                jQuery.Event.prototype.rgb=function(){
                        var x =  this.offsetX || (this.pageX - $(this.target).offset().left),y =  this.offsetY || (this.pageY - $(this.target).offset().top);
                        if (this.target.nodeName!=="CANVAS")return null;
                        return this.target.getContext('2d').getImageData(x,y,1,1).data;
                    }
                

                注意:我的图片 url (src) 来自子域 url

                Note: my image url (src) is from a subdomain url

                推荐答案

                正如其他人所说,您通过从跨域域加载来污染"画布.

                As others have said you are "tainting" the canvas by loading from a cross origins domain.

                https://developer.mozilla.org/en-US/docs/HTML/CORS_Enabled_Image

                但是,您可以通过简单的设置来防止这种情况发生:

                However, you may be able to prevent this by simply setting:

                img.crossOrigin = "Anonymous";
                

                这仅在远程服务器正确设置以下标头时才有效:

                This only works if the remote server sets the following header appropriately:

                Access-Control-Allow-Origin "*"
                

                使用直接链接"选项时,Dropbox 文件选择器是一个很好的例子.我在 oddprints.com 上使用它来将远程 Dropbox 图像 url 中的图像存储到我的画布中,然后将图像数据提交回我的服务器.全部在javascript中

                The Dropbox file chooser when using the "direct link" option is a great example of this. I use it on oddprints.com to hoover up images from the remote dropbox image url, into my canvas, and then submit the image data back into my server. All in javascript

                这篇关于如何修复 getImageData() 错误画布已被跨域数据污染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                How to upload image into HTML5 canvas(如何将图像上传到 HTML5 画布中)
                <legend id='Xc24n'><style id='Xc24n'><dir id='Xc24n'><q id='Xc24n'></q></dir></style></legend>

                  1. <i id='Xc24n'><tr id='Xc24n'><dt id='Xc24n'><q id='Xc24n'><span id='Xc24n'><b id='Xc24n'><form id='Xc24n'><ins id='Xc24n'></ins><ul id='Xc24n'></ul><sub id='Xc24n'></sub></form><legend id='Xc24n'></legend><bdo id='Xc24n'><pre id='Xc24n'><center id='Xc24n'></center></pre></bdo></b><th id='Xc24n'></th></span></q></dt></tr></i><div id='Xc24n'><tfoot id='Xc24n'></tfoot><dl id='Xc24n'><fieldset id='Xc24n'></fieldset></dl></div>
                  2. <tfoot id='Xc24n'></tfoot>

                      <tbody id='Xc24n'></tbody>
                    • <bdo id='Xc24n'></bdo><ul id='Xc24n'></ul>

                          <small id='Xc24n'></small><noframes id='Xc24n'>