@@ -54,9 +54,12 @@ public class AvatarUtil {
5454 new Color (255 , 87 , 34 ),
5555 new Color (121 , 85 , 72 ),
5656 new Color (158 , 158 , 158 ),
57- new Color (96 , 125 , 139 )
57+ new Color (96 , 125 , 139 ),
58+ new Color (3 , 169 , 244 ),
59+ new Color (3 , 169 , 244 ),
5860 };
5961 }
62+ private static String CHARACTERS = "abcdefghijklmnopqrstuvwxyz" ;
6063
6164 private static final String AVATAR_CACHE_ROOT ;
6265 private static final String CUSTOM_AVATAR_CACHE_ROOT ;
@@ -259,7 +262,7 @@ private static Image createAvatar(String sign, String name)
259262 // 抗锯齿
260263 g2d .setRenderingHint (RenderingHints .KEY_ANTIALIASING , RenderingHints .VALUE_ANTIALIAS_ON );
261264 // 画图
262- g2d .setBackground (getColor (name ));
265+ g2d .setBackground (getRuleColor (name ));
263266 g2d .clearRect (0 , 0 , width , height );
264267
265268 // 文字
@@ -290,9 +293,26 @@ private static Image createAvatar(String sign, String name)
290293 return null ;
291294 }
292295
296+ /**
297+ *
298+ * @param identify
299+ * @return
300+ */
301+ private static Color getRuleColor (String identify ){
302+ int pos = CHARACTERS .lastIndexOf (identify .substring (0 ,1 ).toLowerCase ());
303+ if (pos ==-1 ){
304+ pos = (int )Math .round (Math .random ()*colorArr .length );
305+ }else if (pos >=colorArr .length ){
306+ pos = pos - colorArr .length ;
307+ // pos = CHARACTERS.length()%colorArr.length;
308+ }
309+ if (pos ==colorArr .length )pos = colorArr .length -1 ;
310+ return colorArr [pos ];
311+ }
293312
294313 private static Color getColor (String username )
295314 {
315+
296316 int position = username .length () % colorArr .length ;
297317 return colorArr [position ];
298318 }
0 commit comments