html5中如何更新圖片顏色

本文小編為大家詳細介紹“html5中如何更新圖片顏色”,內(nèi)容詳細,步驟清晰,細節(jié)處理妥當,希望這篇“html5中如何更新圖片顏色”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。

成都創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站設(shè)計制作、成都網(wǎng)站設(shè)計、阿克蘇網(wǎng)絡(luò)推廣、小程序開發(fā)、阿克蘇網(wǎng)絡(luò)營銷、阿克蘇企業(yè)策劃、阿克蘇品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)公司為所有大學生創(chuàng)業(yè)者提供阿克蘇建站搭建服務(wù),24小時服務(wù)熱線:13518219792,官方網(wǎng)址:muchs.cn

代碼如下:

<canvas id="c1" width="1220" height = "880" ></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>

讀到這里,這篇“html5中如何更新圖片顏色”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領(lǐng)會,如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

文章題目:html5中如何更新圖片顏色
路徑分享:http://muchs.cn/article30/jehppo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、電子商務(wù)、網(wǎng)站制作網(wǎng)站策劃、外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管