java生成渐变色(生成不同的RGB)

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-23 21:03   33   0
做项目时,有这个需求,不同类型的东西用不同的颜色表示,于是做了如下RGB生成的代码


public static String getRGB(int max,int min,int current){
int a = current-min;
int d = max - min;
int c = 16777215/d;
int b = a*c;
String m = Integer.toHexString(b);
if(m.length()==6)
return "ff"+m;
if(m.length()==5)
return "ff0"+m;
if(m.length()==4)
return "ff00"+m;
if(m.length()==3)
return "ff000"+m;
if(m.length()==2)
return "ff0000"+m;
if(m.length()==1)
return "ff00000"+m;
else
return "ff000000";
}


max为最大值
min为最小值
current为当前值
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP