HOLA EXPERTOS EN JAVASCRIPT, NO PUEDO OBTENER UN OBJETO CON LOS DATOS DE IMAGEN, ESPERO SU VALIOSA AYUDA, SALUDOS


25 de Marzo del 2021

script.js:11 Uncaught DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
at Image.<anonymous> (file:///C:/script.js:11:31)
(anonymous) @ script.js:11
load (async)
(anonymous) @ script.js:9

 

************************************index.html************************************

<!DOCTYPE html>
<html lang="eng">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pixel manipulation</title>
<link rel="stylesheet" type="style.css">
</head>
<body>
<canvas id="canvas"></canvas>

<script src="script.js"></script>
</body>
</html>

 

************************************style.css************************************

body {
background: black;
}
#canvas1{
border: 3px solid white;
top: 50%;
left: 50%;
position: absolute;
width: 800px;
height: 450px;
transform: translate(-50%, -50%);
}

************************************script.js************************************

const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
canvas.width = 2000;
canvas.height = 1550;

const image = new Image();
image.src = 'image1.png';

image.addEventListener('load', function(){
context.drawImage(image, 0, 0, canvas.width, canvas.height);
const scannedImage = context.getImageData(0, 0, canvas.width, canvas.height);
console.log(scannedImage);
})