javascript - how to get pixel color from image using x and y coordinates? -
what tryting take "pixel.jpg" , cosole.log rgb value of pixel @ x , y values determined variable. im assuming need create canvas , scan entire thing using loop.. ??
<meta charset="utf-8"> title>pixel</title> <link href="pixel.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="pixel.js"></script>
<pre id="output"></pre>
draw pixel on canvas. use getimagedata
.
var getpixelcolor = function(img,x,y){ var canvas = document.createelement('canvas'); canvas.width = 1; canvas.height = 1; var ctx = canvas.getcontext('2d'); ctx.drawimage(img,x,y,1,1,0,0,1,1); return ctx.getimagedata(0,0,1,1); }
Comments
Post a Comment