javascript根據(jù)像素點取位置示例
更新時間:2014年01月27日 15:58:29 作者:
這篇文章主要介紹了javascript根據(jù)像素點取位置的示例,大家參考使用吧
復(fù)制代碼 代碼如下:
<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>
相關(guān)文章
JS字符串和數(shù)組如何實現(xiàn)相互轉(zhuǎn)化
這篇文章主要介紹了JS字符串和數(shù)組如何實現(xiàn)相互轉(zhuǎn)化,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-07-07
js 頁面?zhèn)鲄?shù)時 參數(shù)值含特殊字符的問題
解決方法就是利用js的escape函數(shù),這個函數(shù)在解決中文亂碼等方面應(yīng)用的比較廣泛。推薦使用。2009-12-12
JavaScript實現(xiàn)讀取上傳視頻文件的時長和第一幀畫面過程講解
當(dāng)我們做一個后臺系統(tǒng)的音視頻管理模塊時,通常要限制文件的大小和類型,這篇文章主要介紹了JavaScript實現(xiàn)讀取上傳視頻文件的時長和第一幀畫面過程,需要詳細了解實現(xiàn)方法可以參考下文2023-05-05
JavaScript正則表達式小結(jié)(test|match|search|replace|split|exec)
這篇文章主要介紹了JavaScript正則表達式小結(jié)(test|match|search|replace|split|exec)的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友參考下吧2016-12-12
webpack里使用jquery.mCustomScrollbar插件的方法
malihu-custom-scrollbar-plugin是一個依賴jquery的自定義網(wǎng)頁滾動條樣式插件,這篇文章主要介紹了webpack里使用jquery.mCustomScrollbar插件的方法,感興趣的小伙伴們可以參考一下2018-05-05

