How do i tint an image with HTML5 Canvas?

后端 未结 6 2043
粉色の甜心
粉色の甜心 2020-11-30 03:23

My question is, what is the best way to tint an image that is drawn using the drawImage method. The target useage for this is advanced 2d particle-effects (game development)

6条回答
  •  心在旅途
    2020-11-30 03:55

    You have compositing operations, and one of them is destination-atop. If you composite an image onto a solid color with the 'context.globalCompositeOperation = "destination-atop"', it will have the alpha of the foreground image, and the color of the background image. I used this to make a fully tinted copy of an image, and then drew that fully tinted copy on top of the original at an opacity equal to the amount that I want to tint.

    Here is the full code:

    
    
        
            HTML5 Canvas Test
            
        
        
            
                

    Your browser doesn't support canvas.

提交回复
热议问题