Home  >  Article  >  Web Front-end  >  Example of javascript positioning based on pixels_javascript skills

Example of javascript positioning based on pixels_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:02:051211browse

复制代码 代码如下:


    
        

        <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@0;<BR>                    var y = i/400;<BR>                    Pixels.push(new position(x,y));<BR>                }<BR>            }<br><br>        </script>
    

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn