Javascript check if transparent image on canvas has been clicked -


i have canvas, , drew image transparent, , has polygon shape. need check if image has been clicked.

i have cords { x:30, y:20, w:100, h:100 }

i check box or circle click if rigid polygon there pixel click test or convex algorithm(but don't want have specify edges)?

thank you.

one solution implement pixel detection secondary canvas used map.

  1. draw shape onto scene canvas.
  2. draw exact shape onto second canvas, set color rgb(0,0,0).
  3. store color reference in sort of map reference first 'shape'

e.g.

var pixelmap = {   '000' : 'rectangle 1',   '001' : 'rectangle 2' }; 

every time draw new shape canvas, increase rgb 1. unless have on 16.7 million shapes (256^3), method should suffice.

heres example implementation : https://jsfiddle.net/mikeschultz/nbtnxpf2/


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -