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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -