I have  to fill an image with r g b a component. It is working with function something.fillStyle = " rgba ("+r+","+g+","+b+","+a+")"; but i want to use something.fillStyle = value where value is the color value in hex of the form alpha r g b. When value is #ffff00 (yellow) it is fine but when I use a value with alpha (#ffffff00) it is always black. Is there any way to do this?
            Asked
            
        
        
            Active
            
        
            Viewed 805 times
        
    0
            
            
         
    
    
        Wladimir Palant
        
- 56,865
- 12
- 98
- 126
 
    
    
        user894554
        
- 258
- 5
- 18
2 Answers
1
            This is not possible, see http://www.w3.org/TR/css3-color/#numerical. Hex color values don't allow setting the "alpha" value, that's only possible with rgba and hsla.
 
    
    
        Wladimir Palant
        
- 56,865
- 12
- 98
- 126
0
            
            
        It is possible, if you convert the hex to rgb and then add your alpha value. Also, you can set the globalAlpha which will apply even if the rest of the colors in the function are using hex colors.
if (myAlpha) {
    ctx.globalAlpha = myAlpha;
}
take a look at the hextorbg function here.
 
    