Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's possible using canvas element. Get pixel data of image using <code>getImageData</code> method of canvas and check rgb value. To use <code>getImageData</code> you need to put your script file and image on same domain because of cross domain issue. In this case, the divider is not to be visible on #00ff00.</p> <p><a href="http://edwardrockhands.com/test/triforce.html" rel="nofollow">Sample</a></p> <p>HTML:</p> <pre><code>&lt;canvas id="canvas"&gt;&lt;/canvas&gt; </code></pre> <p>Javascript:</p> <pre><code>$(document).ready(function(){ var canvas=document.getElementById("canvas"); var ctx=canvas.getContext("2d"); var image=document.createElement("img"); image.onload=function(){ canvas.width = image.width; canvas.height = image.height; ctx.fillStyle="#00ff00"; ctx.fillRect(0,0,canvas.width,canvas.width); ctx.drawImage(image,0,0); init(); } image.src="Triforce.png"; function init(){ var imageData = ctx.getImageData(0, 0, image.width, image.height); var data = imageData.data; canvas.addEventListener('mousemove', function(evt) { var mousePos = getMousePos(canvas, evt); var x = mousePos.x; var y = mousePos.y; ctx.clearRect(0,0,canvas.width,canvas.height); ctx.fillStyle="#00ff00"; ctx.fillRect(0,0,canvas.width,canvas.width); ctx.drawImage(image,0,0); ctx.fillRect(x, 0, canvas.width,canvas.height); ctx.fillStyle="#0000ff"; for(var i=x;i&lt;x+10;i++){ for(var j=0;j&lt;image.height;j++){ var red = data[((image.width * j) + i) * 4]; var green = data[((image.width * j) + i) * 4 + 1]; var blue = data[((image.width * j) + i) * 4 + 2]; var alpha = data[((image.width * j) + i) * 4 + 3]; if(!(red==0 &amp;&amp; green==255 &amp;&amp; blue==0)){ ctx.fillRect(i,j,1,1); } } } }, false); } function getMousePos(canvas, evt) { var rect = canvas.getBoundingClientRect(); return { x: evt.clientX - rect.left, y: evt.clientY - rect.top }; } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload