These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:10 pm Advanced search

Image pixel color help needed

Here you can discuss things related to HTML and the Web in general that do not fit in to other categories.

Image pixel color help needed

Postby albert26 » Mon Feb 07, 2011 10:25 pm

Hi guys, I have one question that I suffer all day.
So if there is someone who has no problem to write code to read the color pixels. for example:
I need to load the image in canvas element. read red, green and blue values of pixel located at (26x30) in gs.png
Code: Select all
<html>
<head>
<script type="application/x-javascript">
    function draw() {
      var ctx = document.getElementById('canvas').getContext('2d');
      var img = new Image();
      img.src = 'gs.png';
      img.onload = function()
     {
   var data = imgd.getImageData(26, 30, 1, 1).data;
   var color = new Color([data[0], data[1], data[2]]);
      }
    }
    </script>
</head>
<body onLoad="draw();">
<canvas id="canvas" width="180" height="130"></canvas>
<img src="gs.png"/>
</body>
</html>


I need answer in alert, new variable, whatever...
THX
albert26
<h6>
 
Posts: 1
Joined: Mon Feb 07, 2011 10:08 pm

Re: Image pixel color help needed

Postby zcorpan » Wed Mar 30, 2011 4:30 pm

You need to do ctx.getImageData, not img.getImageData
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest