Skip to content

Instantly share code, notes, and snippets.

@leventeren
Created February 2, 2024 12:37
Show Gist options
  • Save leventeren/0b61384929559c79c1d384aae89dfbe1 to your computer and use it in GitHub Desktop.
Save leventeren/0b61384929559c79c1d384aae89dfbe1 to your computer and use it in GitHub Desktop.
Hex To Color
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