复制代码代码如下:
<html>
<Body>
<Canvas id = "Canvas" style = "de fondo: #000;"/>
<script>
posición de función (x, y) {
this.x = x;
this.y = y;
}
var lienvas = document.getElementById ('Canvas'),
ctx = canvas.getContext ('2d');
ancho = canvas.width,
altura = Canvas.Height;
ctx.fillstyle = "#FF0000";
ctx.font = "20px arial";
ctx.FillText ("妈妈", 10,50);
var pixs = ctx.getImagegedata (0,0, ancho, altura) .data;
var píxeles = new Array ();
para (var i = 0; i <pixs.length; i+= 4)
{
var r = pixs [i],
g = pixs [i+1],
b = pixs [i+2],
a = pixs [i+3];
if (r! = 0 || g! = 0 || b! = 0) {
var x = i%400;
var y = i/400;
Píxeles.push (nueva posición (x, y));
}
}
</script>
</body>
</html>