I know this is an old question, but there is now a Color.luminance(int)
that already does what the selected answer suggests (API 24+)
/**
* Returns the relative luminance of a color.
* <p>
* Assumes sRGB encoding. Based on the formula for relative luminance
* defined in WCAG 2.0, W3C Recommendation 11 December 2008.
*
* @return a value between 0 (darkest black) and 1 (lightest white)
*/
public static float luminance(@ColorInt int color) {
ColorSpace.Rgb cs = (ColorSpace.Rgb) ColorSpace.get(ColorSpace.Named.SRGB);
DoubleUnaryOperator eotf = cs.getEotf();
double r = eotf.applyAsDouble(red(color) / 255.0);
double g = eotf.applyAsDouble(green(color) / 255.0);
double b = eotf.applyAsDouble(blue(color) / 255.0);
return (float) ((0.2126 * r) + (0.7152 * g) + (0.0722 * b));
}
There is also a difference between luminance and brightness:
As per wikipedia:
A more perceptually relevant alternative is to use luma, Y′, as a lightness dimension (fig. 12d). Luma is the weighted average of gamma-corrected R, G, and B, based on their contribution to perceived lightness, long used as the monochromatic dimension in color television broadcast. For sRGB, the Rec. 709 primaries yield Y′709, digital NTSC uses Y′601 according to Rec. 601 and some other primaries are also in use which result in different coefficients.[26][J]
Y 601 ′ = 0.2989 * R + 0.5870 * G + 0.1140 * B (SDTV)
Y 240 ′ = 0.212 * R + 0.701 * G + 0.087 * B (Adobe)
Y 709 ′ = 0.2126 * R + 0.7152 * G + 0.0722 * B (HDTV)
Y 2020 ′ = 0.2627 * R + 0.6780 * G + 0.0593 * B (UHDTV, HDR)
So, you would first need to understand if what you want is actually brightness (a average of the sum of R, G and B on RGB), or luminance which accounts for the human eye perception.
For completeness, if you want the actual brightness, that would be the V value on an HSV representation of color, so you could use:
val hsv = FloatArray(3)
Color.colorToHSV(color, hsv)
val brightness = hsv[2]