diff --git a/source/MonoGame.Extended/ColorExtensions.cs b/source/MonoGame.Extended/ColorExtensions.cs index 452ad37ff..b32c5f151 100644 --- a/source/MonoGame.Extended/ColorExtensions.cs +++ b/source/MonoGame.Extended/ColorExtensions.cs @@ -81,5 +81,26 @@ public static HslColor ToHsl(this Color c) return new HslColor(h, s, l); } + + /// + /// Returns a new value based on a packed value in the ABGR format. + /// + /// + /// This is useful for when you have HTML hex style values such as #123456 and want to use it in hex format for + /// the parameter. Since Color's standard format is RGBA, you would have to do new Color(0xFF563212) since R + /// is the LSB. With this method, you can write it the same way it is written in HTML hex by doing + /// >ColorExtensions.FromAbgr(0x123456FF); + /// + /// The packed color value in ABGR format + /// The value created + public static Color FromAbgr(uint abgr) + { + uint rgba = (abgr & 0x000000FF) << 24 | // Alpha + (abgr & 0x0000FF00) << 8 | // Blue + (abgr & 0x00FF0000) >> 8 | // Green + (abgr & 0xFF000000) >> 24; // Red + + return new Color(rgba); + } } }