Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RGB to ARGB conversion in Android

Tags:

android

colors

I have RGB code for a color. For example Gray color (118,118,118). How can I use it in setPixel() function? Because setPixel() function wants argb for color.

like image 385
ekremk Avatar asked Jun 05 '13 14:06

ekremk


2 Answers

int color = Color.argb(255, 118, 118, 188);

if you want full opacity.

like image 188
Blackbelt Avatar answered Nov 15 '22 03:11

Blackbelt


The first (a) value represents the Alpha channel, or in plain language: the transparency. (How much you can see through this colour, to the images behind it)

The value is one byte, so acceptable values range from 0 to 255.

As per the answer above, a value of 255 means your colour will be completely opaque (solid).
A value of 128 will give you 50% transparency.
A value of 0 will make your object completely invisible, regardless of your colour value, but the object still exists, like a sheet of perfectly clear glass, if you allow the analogy.

This can be useful for e.g secret/hidden/invisible buttons, creating easter eggs, or specific cases of UI tuning.

like image 41
Mtl Dev Avatar answered Nov 15 '22 03:11

Mtl Dev