首页 >web前端 >js教程 >javascript根据像素点取位置示例_javascript技巧

javascript根据像素点取位置示例_javascript技巧

WBOY
WBOY原创
2016-05-16 17:02:051227浏览

复制代码 代码如下:


    
        

        <script><BR> function position (x,y){<BR> this.x = x;<BR> this.y = y;<BR> }<br><br> var canvas = document.getElementById('canvas'),<BR> ctx = canvas.getContext('2d');<BR> width = canvas.width,<BR> height = canvas.height;<BR> ctx.fillStyle = "#FF0000";<BR> ctx.font = "20px Arial";<BR> ctx.fillText("妈妈",10,50);<br><br> var pixs = ctx.getImageData(0,0,width,height).data;<BR> var Pixels = new Array();<br><br> for(var i=0;i<pixs.length;i+= 4)<BR> {<BR> var r = pixs[i],<BR> g = pixs[i+1],<BR> b = pixs[i+2],<BR> a = pixs[i+3];<br><br> if(r != 0 || g != 0 || b != 0 ){<BR> var x = i%400;<BR> var y = i/400;<BR> Pixels.push(new position(x,y));<BR> }<BR> }<br><br> </script>
    

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn