Created
August 25, 2014 05:57
-
-
Save yim1990/064adb78ee168091da4d to your computer and use it in GitHub Desktop.
Hex color extraction from string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StringHexUtil { | |
public static String stringToRgbHash(String source) { | |
int hash=source.hashCode(); | |
int r = (hash & 0xFF0000) >> 16; | |
int g = (hash & 0x00FF00) >> 8; | |
int b = hash & 0x0000FF; | |
return "#"+Integer.toHexString(r)+Integer.toHexString(g)+Integer.toHexString(b); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It`s useful when you want to transform string into hex web color.
Same string represents same color.