Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public struct Color
- {
- public byte A, R, G, B;
- public const uint White = 0x000000FF;
- public const uint Green = 0x00FF00FF;
- public const uint Red = 0xFF0000FF;
- public const uint Blue = 0x0000FFFF;
- /// <summary>
- /// Creates a Color structure from the four ARGB component (alpha, red, green, and blue) values.
- /// </summary>
- /// <param name="a">The Alpha (opacity) value of the color.</param>
- /// <param name="r">The Red value of the color.</param>
- /// <param name="g">The Green value of the color.</param>
- /// <param name="b">The Blue value of the color.</param>
- public Color(float a, float r, float g, float b)
- {
- A = (byte)(a * 255);
- R = (byte)(r * 255);
- G = (byte)(g * 255);
- B = (byte)(b * 255);
- }
- /// <summary>
- /// Creates a Color structure from the four ARGB component (alpha, red, green, and blue) values.
- /// </summary>
- /// <param name="a">The Alpha (opacity) value of the color.</param>
- /// <param name="r">The Red value of the color.</param>
- /// <param name="g">The Green value of the color.</param>
- /// <param name="b">The Blue value of the color.</param>
- public Color(byte a, byte r, byte g, byte b)
- {
- A = a;
- R = r;
- G = g;
- B = b;
- }
- public override string ToString()
- {
- return "0x" + string.Format("{0:x}", (uint)this).ToUpper();
- }
- public static implicit operator uint(Color color)
- {
- return System.BitConverter.ToUInt32(new byte[] { color.A, color.B, color.G, color.R }, 0);
- }
- public static implicit operator Color(uint uColor)
- {
- Color color = new Color();
- byte[] bytes = System.BitConverter.GetBytes(uColor);
- color.A = bytes[0];
- color.B = bytes[1];
- color.G = bytes[2];
- color.R = bytes[3];
- return color;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement