How to re-tint a grayscale image on canvas

前端 未结 3 892
清歌不尽
清歌不尽 2021-01-15 16:27

Is there any quick way to colorize greyscale icon (png image with transparent background) when drawing it on canvas? By colorize I mean turning greyscale icon into lets say

3条回答
  •  日久生厌
    2021-01-15 17:08

    You can achieve it using css classes. Check the below example P.S: Source: w3Schools

    img {
      width: 33%;
      height: auto;
      float: left;
      max-width: 235px;
    }
    .blur {
      -webkit-filter: blur(4px);
      filter: blur(4px);
    }
    .brightness {
      -webkit-filter: brightness(250%);
      filter: brightness(250%);
    }
    .contrast {
      -webkit-filter: contrast(180%);
      filter: contrast(180%);
    }
    .grayscale {
      -webkit-filter: grayscale(100%);
      filter: grayscale(100%);
    }
    .huerotate {
      -webkit-filter: hue-rotate(180deg);
      filter: hue-rotate(180deg);
    }
    .invert {
      -webkit-filter: invert(100%);
      filter: invert(100%);
    }
    .opacity {
      -webkit-filter: opacity(50%);
      filter: opacity(50%);
    }
    .saturate {
      -webkit-filter: saturate(7);
      filter: saturate(7);
    }
    .sepia {
      -webkit-filter: sepia(100%);
      filter: sepia(100%);
    }
    .shadow {
      -webkit-filter: drop-shadow(8px 8px 10px green);
      filter: drop-shadow(8px 8px 10px green);
    }
    
    
      

    Note: The filter property is not supported in Internet Explorer, Edge 12, or Safari 5.1 and earlier.

    Pineapple Pineapple Pineapple Pineapple Pineapple Pineapple Pineapple Pineapple Pineapple Pineapple Pineapple

    Refer this link for learning what filter style can do.

    ClickMe

提交回复
热议问题