[JAVA] Android development, brightness adjustment in HSV from RGB color,

I have been in charge of iOS for my work so far, but I am also involved in Android development probably because there are few engineers in the field now. I am a young person, but I am studying Java because it is a very valuable experience in my future career development. (The trend is probably Kotlin) So I'll leave behind the methods that got stuck in practice.

Brightness adjustment from Color


    public int convertColorFromHSV(final int color, final float brightness) {
        final float[] hsv = new float[3];
        Color.colorToHSV(color, hsv);
        hsv[2] -= brightness;
        return Color.HSVToColor(hsv);

You can now adjust the brightness. Since the maximum brightness is 1 (100%), it is an adjustment of what percentage to darken from 1. For example, if you want to reduce the brightness by 15% from the original color Substitute color for the original color and 0.15 for brightness.

(Reference) Android Document Color https://developer.android.com/reference/android/graphics/Color

By the way Brightness is a type of HSV color space. HSV space is one of the color spaces handled by computer graphics. Hue, Saturation Chroma, Brightness Lightness Value It is composed of 3 components.

The Color class is an RGB color space or an ARGB color space.

With the above method

Color.colorToHSV(color, hsv);

When you hit, it becomes an array of float [] hsv Hue, saturation, and lightness are stored corresponding to indexes 0, 1, 2 of the hsv array. hsv [0]: Hue hsv [1]: Saturation hsv [2]: Brightness is.

Values from 0.0 to 360.0 are stored for hue. saturation, Values from 0.0 to 1.0 are stored for lightness.

I was addicted to it for about an hour without knowing how to use this colorToHSV method.

Recommended Posts

Android development, brightness adjustment in HSV from RGB color,
I tried to summarize Android development, RGB, hexadecimal number, color implementation from resource files
Convert from color temperature to RGB (sRGB)
What to do if build from command line fails in Android development environment
[Android development] Get an image from the server in Java and set it in ImageView! !!