javascript根据像素点取位置示例
时间:2023-09-03 22:58:54
<html>
<body>
<canvas id="canvas" width="100" height="100" style="background-color: #000;"/>
<script>
function position (x,y){
this.x = x;
this.y = y;
}
var canvas = document.getElementById('canvas'),
ctx = canvas.getContext('2d');
width = canvas.width,
height = canvas.height;
ctx.fillStyle = "#FF0000";
ctx.font = "20px Arial";
ctx.fillText("妈妈",10,50);
var pixs = ctx.getImageData(0,0,width,height).data;
var Pixels = new Array();
for(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;
Pixels.push(new position(x,y));
}
}
</script>
</body>
</html>
标签:javascript,像素
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用pandas 将DataFrame转化成dict
2022-08-11 17:46:33
利用Python小工具实现3秒钟将视频转换为音频
2023-05-26 21:11:34
![](https://img.aspxhome.com/file/2023/9/124199_0s.jpg)
Java 数据库连接池c3p0 介绍
2024-01-22 02:44:24
Python全角与半角之间相互转换的方法总结
2023-12-25 03:50:50
![](https://img.aspxhome.com/file/2023/3/135263_0s.png)
伪静态下不能使用FCKeditor的解决方法
2023-02-03 06:54:20
正则 global 属性介绍
2008-03-18 20:50:00
pytorch 多个反向传播操作
2021-03-05 02:21:49
![](https://img.aspxhome.com/file/2023/3/128473_0s.jpg)
PHP 应用容器化以及部署方法
2023-11-14 15:45:06
![](https://img.aspxhome.com/file/2023/8/80518_0s.jpg)
使用XML库的方式,实现RPC通信的方法(推荐)
2021-11-15 14:00:42
![](https://img.aspxhome.com/file/2023/5/95385_0s.png)
利用C#实现分布式数据库查询
2024-01-24 18:25:28
![](https://img.aspxhome.com/file/2023/7/116547_0s.jpg)
解决Jrebel用户名中文导致用不了的问题
2023-04-10 05:20:15
![](https://img.aspxhome.com/file/2023/1/127241_0s.png)
浅谈Python数学建模之整数规划
2021-12-01 18:26:07
![](https://img.aspxhome.com/file/2023/6/134796_0s.jpg)
MySQL简化输入小技巧
2024-01-13 15:49:33
python关于excel多个sheet的导入导出方式
2021-03-15 04:40:19
![](https://img.aspxhome.com/file/2023/0/130970_0s.png)
MySQL中DATE_FORMAT()函数的具体使用
2024-01-16 14:03:49
python3.4中清屏的处理方法
2023-11-14 04:09:21
![](https://img.aspxhome.com/file/2023/3/64603_0s.jpg)
一步步教你用python给女朋友写个微信自动提醒的程序
2022-09-03 16:50:25
![](https://img.aspxhome.com/file/2023/0/115020_0s.jpg)
python读取图片任意范围区域
2023-07-16 06:26:21
![](https://img.aspxhome.com/file/2023/3/95193_0s.jpg)
python知识:装饰器@property到底有啥用途
2022-07-23 12:25:45
![](https://img.aspxhome.com/file/2023/3/128483_0s.png)
tensorflow:指定gpu 限制使用量百分比,设置最小使用量的实现
2021-06-03 17:02:32