Skip to content

Instantly share code, notes, and snippets.

@enue
Created August 29, 2016 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enue/9f682136efdd503484c5c7fccdabb3fe to your computer and use it in GitHub Desktop.
Save enue/9f682136efdd503484c5c7fccdabb3fe to your computer and use it in GitHub Desktop.
argb parser
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