I'm trying to find the RGBA value of specific pixels in an image. To do so, i put the image in a canvas, got the canvas context and then used the getImageData method. I get a "The operation is insecure" error.
In an html file i only have a canvas element with "canvas" as id.
I found somewhere that the problem might be with the origin of the file. To be honest i don't really understand what that means but in the thread i read, it was said that changing the crossOrigin to anonymous would fix my problem. It unfortunately didn't.
My Js code :
let canvas = document.getElementById("canvas");
canvas.width = 640;
canvas.height = 480;
let ctx = canvas.getContext("2d");
let img = new Image();
img.src = "image1.bmp";
ctx.drawImage(img, 0, 0, 640, 480);
let imgData = ctx.getImageData(0, 0, 640, 480);
My HTML code :
<!DOCTYPE html>
<html>
<script src="act.js" defer></script>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<canvas id="canvas"></canvas>
<style type="text/css">
canvas {
border: 1px solid black;
width: 640px;
height: 480px;
}
</style>
</body>
</html>