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";
This will work if the remote server has the headers set appropriately −
Access-Control-Allow-Origin "*"
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!