Created
February 2, 2024 12:37
-
-
Save leventeren/0b61384929559c79c1d384aae89dfbe1 to your computer and use it in GitHub Desktop.
Hex To Color
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
Color HexToColor(string hex) | |
{ | |
hex = hex.TrimStart('#'); // Eğer renk kodu başında '#' varsa kaldır | |
Color color = new Color(); | |
color.r = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber) / 255f; | |
color.g = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber) / 255f; | |
color.b = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber) / 255f; | |
if (hex.Length == 8) | |
{ | |
color.a = byte.Parse(hex.Substring(6, 2), System.Globalization.NumberStyles.HexNumber) / 255f; | |
} | |
else | |
{ | |
color.a = 1f; | |
} | |
return color; | |
} | |
//Color renk = HexToColor("#C0C0C0"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment