• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    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>
    上一篇:浅谈html5 响应式布局
    下一篇:HTML5 transform三维立方体实现360无死角三维旋转效果
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    html5 更新图片颜色示例代码 html5,更新,图片,颜色,示例,