javascript - How to get pixel position -


i feel dumb asking this, bear me. know formula pixel position in linear array:

pos = (y * width + x) * 4 

which works fine. jsfiddle. before image/table linearized, same formula doesn't work. need use (let's discard rgba simplicity)

pos = (y-1) * width + x 

enter image description here

why that? i'm missing simple.


update: knew simple. silly me.

enter image description here

in javascript pixel coordinates start @ 0, same coordinate system. pixel referenced top left corner, first pixel @ (0,0) , next going right (1,0) (2,0) , on. pixel below @ (0,1) give coordinates relative origin (0,0).

we give sizes counts. when using width , height pixel counts , start @ 1 when count. 100th pixel on row 99. same 21th century in year 2015.

so no need subtract 1 pixel coordinates.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -