How to fix getImageData() error 'canvas has been contaminated by cross-domain data' in HTML?

WBOY
Release: 2023-09-12 15:53:02
forward
575 people have browsed it

How to fix getImageData() error canvas has been contaminated by cross-domain data in HTML?

The crossOrigin attribute allows images loaded from external sources to be used in the canvas as if they were loaded from the current source.

Using images without CORS approval pollutes the canvas. Once the canvas is contaminated, there is no way to get the data back from the canvas. By loading the canvas from a cross-origin domain, you are polluting the canvas.

You can prevent this from happening by setting −.

img.crossOrigin = "Anonymous";
Copy after login

This will work if the remote server has the headers set appropriately −

Access-Control-Allow-Origin "*"
Copy after login

The above is the detailed content of How to fix getImageData() error 'canvas has been contaminated by cross-domain data' in HTML?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!