gpt4 book ai didi

java - 使用一些键在 android 中创建随机颜色(对于相同的键,它应该生成相同的颜色)

转载 作者:行者123 更新时间:2023-11-29 18:26:30 24 4
gpt4 key购买 nike

我正在开发一个聊天应用程序,为此,我需要为用户个人资料图片生成随机颜色。但是我需要为同一个人生成相同的颜色。我有一个唯一的用户 ID。我不喜欢在生成一次颜色代码后保存颜色代码。所以,基本上我需要一种方法来获取颜色代码。

int getUserColourCode(String userId) {
//code needed.
//It should return random colour code (int) with respect to user id.
//I would like to exclude light shade colours (dark and semi dark colours are preferred).
}

提前致谢。

最佳答案

int getUserColourCode(String userId) { StringBuilder input1 = new StringBuilder();

input1.append(userId);
input1=input1.reverse();
String pair[]={"0","0","0","0","0","0","0","0"};
char[] character = input1.toString().toCharArray();

for(int i=0;i<character.length;i++)
{
pair[i]=String.valueOf(character[i]);
}
int color = Color.argb((Integer.parseInt(pair[0]+pair[1])*2)+50, (Integer.parseInt(pair[2]+pair[3])*2)+50, (Integer.parseInt(pair[4]+pair[5])*2)+50, (Integer.parseInt(pair[6]+pair[7])*2)+50);
return color;

关于java - 使用一些键在 android 中创建随机颜色(对于相同的键,它应该生成相同的颜色),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58654973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com