国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

html5 更新圖片顏色示例代碼

2024-04-25 20:31:29
字體:
來源:轉載
供稿:網友

html5 更新圖片顏色的具體實現方法

<canvas id="c1" width="1220" height = "880" style="background: none repeat scroll 0% 0% transparent; "></canvas>
<script>
var cID = "c1";
var image = new Image();
image.src = "Eye/item_eye_1.png";
image.onload = function () {
recolorImage(cID,image, 0, 0, 0, 255, 0, 0);
}
function recolorImage(c,img, oldRed, oldGreen, oldBlue, newRed, newGreen, newBlue) {
var c = document.getElementById(c);
var ctx = c.getContext("2d");
var w = img.width;
var h = img.height;
c.width = w;
c.height = h;
// draw the image on the temporary canvas
ctx.drawImage(img, 0, 0, w, h);
// pull the entire image into an array of pixel data
var imageData = ctx.getImageData(0, 0, w, h);
// examine every pixel,
// change any old rgb to the new-rgb
for (var i = 0; i < imageData.data.length; i += 4) {
// is this pixel the old rgb?
if (imageData.data[i] == oldRed && imageData.data[i + 1] == oldGreen && imageData.data[i + 2] == oldBlue) {
// change to your new rgb
imageData.data[i] = newRed;
imageData.data[i + 1] = newGreen;
imageData.data[i + 2] = newBlue;
}
}
// put the altered data back on the canvas
ctx.putImageData(imageData, 0, 0);
}
</script>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肥东县| 昭觉县| 昌邑市| 九江市| 陵川县| 两当县| 大新县| 闸北区| 清新县| 二连浩特市| 昌邑市| 青川县| 兴义市| 张家川| 武威市| 永兴县| 大新县| 左贡县| 六枝特区| 同心县| 廉江市| 宜春市| 抚宁县| 莲花县| 临沭县| 龙门县| 喀喇| 灵丘县| 隆安县| 弥渡县| 宜川县| 湟中县| 萨迦县| 浙江省| 宣化县| 淮阳县| 筠连县| 伊宁县| 清河县| 苗栗县| 城市|