Skip to content Skip to sidebar Skip to footer

How To Transform Hex Color Into Float 0-1?

I need process a hex string value to floating color. The real color is (in RGBA format) { 0.63671875f, 0.76953125f, 0.22265625f, 1.0f } Is green, when 0 is equivalent to 00 and 1

Solution 1:

I fount the solution:

privatefloat[] getFloatArrayFromARGB(String argb){
    int color_base = Color.parseColor(argb);
    int red = Color.red(color_base);
    int green = Color.green(color_base);
    int blue = Color.blue(color_base);
    int alpha = Color.alpha(color_base);

    returnnewfloat[]{
            (red / 255f),
            (green / 255f),
            (blue / 255f),
            (alpha / 255f)
    };
}

Use:

Stringargb="#FFFF0000";
float[] color = this.getFloatArrayFromARGB(argb);
GLES20.glUniform4fv(mColorHandle, 1, color, 0);

:D Now use ARGB format to paint 3D objects with OpenGL

Post a Comment for "How To Transform Hex Color Into Float 0-1?"