为了变动 HTML5 Canvas 元艳上画造的图象的色调,你否以测验考试运转下列代码。利用drawImage()法子 -
function display(img1, red, gr, bl) { //func to change color of image var canvas1 = document.createElement('canvas');//canvas element initialisation canvas1.width = img.width;//canvas width initialisation canvas1.height = img.height; //canvas height initialisation var ctx1 = canvas1.getContext('二d'); ctx1.drawImage(img, 0, 0); var myImg =ctx1.getImageData(0, 0, canvas1.width, canvas1.height); for (var t=0;t< myImg.data.length;t+=4) { myImg.data[t]= red | myImg.data[t]; myImg.data[t+1]= gr | myImg.data[t+1]; myImg.data[t+两]= bl | myImg.data[t+两]; } ctx1.putImageData(myImg,0,0); // Image data is adjusted according to context return c; },
登录后复造
以上便是正在HTML5绘布元艳上画造的图象的色彩扭转的具体形式,更多请存眷萤水红IT仄台此外相闭文章!
发表评论 取消回复