Created
August 29, 2016 21:43
-
-
Save enue/9f682136efdd503484c5c7fccdabb3fe to your computer and use it in GitHub Desktop.
argb parser
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
static public class ColorUtil | |
{ | |
static public bool TryParseArgbString(string argb, out Color color) | |
{ | |
if (ColorUtility.TryParseHtmlString(argb, out color)) | |
{ | |
var a = color.r; | |
color.r = color.g; | |
color.g = color.b; | |
color.b = color.a; | |
color.a = a; | |
return true; | |
} | |
return false; | |
} | |
// αのないRGBにも対応したいならこっち | |
public static Color32 ParseArgb(string argb) | |
{ | |
var value = System.Convert.ToInt32(argb.TrimStart('#'), 16); | |
var a = (value >> 24) & 0xff; | |
var r = (value >> 16) & 0xff; | |
var g = (value >> 8) & 0xff; | |
var b = value & 0xff; | |
return new Color32((byte)r, (byte)g, (byte)b, (byte)a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment