为了更改 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('2d'); 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+2]= bl | myImg.data[t+2]; } ctx1.putImageData(myImg,0,0); // Image data is adjusted according to context return c; },
以上就是在HTML5画布元素上绘制的图像的颜色改变的详细内容,更多请关注php中文网其它相关文章!
已抢64990个
抢已抢27589个
抢已抢14977个
抢已抢7439个
抢已抢9397个
抢已抢18991个
抢