Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the alpha from a colour but retain its texture

I have a colour #6A8F6509

I wish to remove the Alpha part of that colour and be left with only RGB components (i.e. #RRGGBB).

The resulting colour must look identical to the initial one without the transparency.

How do I go about this on Android's Java?

Update: The initial background is always white (#FFF)

like image 649
Bosah Chude Avatar asked Oct 12 '11 13:10

Bosah Chude


4 Answers

int newColor = oldColor | 0xFF000000;
like image 140
Graham Borland Avatar answered Nov 16 '22 05:11

Graham Borland


If you want to do it with the code you can try following code:

    static int stripAlpha(int color){
    return Color.rgb(Color.red(color), Color.green(color), Color.blue(color));
}
like image 27
Nikolay Ivanov Avatar answered Nov 16 '22 05:11

Nikolay Ivanov


For each color: C' = C(a/255) + 255(1-(a/255))

So for #6A8F6509:

R' = 143(106/255) + 255(1-(106/255) = (approx) 208

G' = 101(106/255) + 255(1-(106/255) = (approx) 191

B' = 9(106/255) + 255(1-(106/255) = (approx) 153

So your answer should be: #D0BF99, if my math is correct. This only applies to an all white background as well - for a non-white background, the second addend should have the appropriate corresponding color value of the background instead of 255.

-- EDIT --

Looking at the formula again, I'm not entirely sure whether the formula gets applied to each color or the entire color (a quick visual test should be able to tell you - I'm guessing per color). I should point out that this is the formula direct from the Alpha Compositing wiki page:

http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending

like image 5
LJ2 Avatar answered Nov 16 '22 06:11

LJ2


try

#FF8F6509

the first two digits indicate the alpha value of any color.

like image 1
Yashwanth Kumar Avatar answered Nov 16 '22 06:11

Yashwanth Kumar