Home  >  Article  >  Web Front-end  >  How to fix getImageData() error "canvas has been contaminated by cross-domain data" in HTML?

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

WBOY
WBOYforward
2023-09-12 15:53:02535browse

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";

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete