如何将十六进制颜色转换为浮点0-1? [英] How to transform hex color into float 0-1?
本文介绍了如何将十六进制颜色转换为浮点0-1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将十六进制字符串值处理为浮动颜色。
I need process a hex string value to floating color.
真正的颜色是(以RGBA格式)
The real color is (in RGBA format)
{ 0.63671875f, 0.76953125f, 0.22265625f, 1.0f }
$ b b
当0等于00,1为FF时为绿色。但是需要将颜色转换为0-255十进制以计算从0到255的%,并设置浮点值。
Is green, when 0 is equivalent to 00 and 1 is FF. But need convert the color to 0-255 decimal to calculate the % from 0 to 255 and set the float value.
如何通过示例转换 #AABBCCFF
到float数组?
How to transform by example #AABBCCFF
to float array?
当parsecolor有整数值时:
When parsecolor i have the integer value:
Color.parseColor("#AABBCCFF");
但是如何将整数转换为float中的每个颜色?红绿蓝和alpa
But how transform the integer to each color in float? red green blue and alpa
推荐答案
我提出了解决方案:
private float[] 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);
return new float[]{
(red / 255f),
(green / 255f),
(blue / 255f),
(alpha / 255f)
};
}
使用:
String argb = "#FFFF0000";
float[] color = this.getFloatArrayFromARGB(argb);
GLES20.glUniform4fv(mColorHandle, 1, color, 0);
:D现在使用ARGB格式用OpenGL绘制3D对象
:D Now use ARGB format to paint 3D objects with OpenGL
这篇关于如何将十六进制颜色转换为浮点0-1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文