using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { /// The RGBQUAD structure describes a color consisting of relative intensities of red, green, and blue. [PInvokeData("Wingdi.h", MSDNShortId = "dd162938")] [StructLayout(LayoutKind.Sequential, Size = 4)] public struct RGBQUAD : IEquatable { /// The intensity of blue in the color. public byte rgbBlue; /// The intensity of green in the color. public byte rgbGreen; /// The intensity of red in the color. public byte rgbRed; /// This member is reserved and must be zero. public byte rgbReserved; /// Initializes a new instance of the struct. /// The intensity of the red color. /// The intensity of the green color. /// The intensity of the blue color. public RGBQUAD(byte r, byte g, byte b) { rgbRed = r; rgbGreen = g; rgbBlue = b; rgbReserved = 0; } /// Gets a value indicating whether any transparency is defined. /// if this value is transparent; otherwise, . public bool IsTransparent => rgbReserved == 0; /// Gets or sets the color associated with the structure. /// The color. public COLORREF Color { get => new(rgbRed, rgbGreen, rgbBlue) { A = rgbReserved }; set { rgbReserved = value.A; rgbBlue = value.B; rgbGreen = value.G; rgbRed = value.R; } } /// public override bool Equals(object obj) => obj is RGBQUAD q && Equals(q); /// Determines whether the specified object is equal to the current object. /// The object to compare with the current object. /// if the specified object is equal to the current object; otherwise, . public bool Equals(RGBQUAD q) => q.rgbBlue == rgbBlue && q.rgbGreen == rgbGreen && q.rgbRed == rgbRed && q.rgbReserved == rgbReserved; /// public override int GetHashCode() => unchecked((int)(uint)this); /// public override string ToString() => $"{{R={rgbRed},G={rgbGreen},B={rgbBlue}}}"; /// Performs an implicit conversion from to . /// The value. /// The result of the conversion. public static implicit operator uint(RGBQUAD c) { unsafe { return *(uint*)&c; } } /// Performs an implicit conversion from to . /// The value. /// The result of the conversion. public static implicit operator RGBQUAD(COLORREF c) => new() { Color = c }; /// Performs an implicit conversion from to . /// The value. /// The result of the conversion. public static implicit operator COLORREF(RGBQUAD c) => c.Color; /// Performs an implicit conversion from to . /// The value. /// The result of the conversion. public static implicit operator RGBQUAD(System.Drawing.Color c) => new() { Color = c }; /// Performs an implicit conversion from to . /// The value. /// The result of the conversion. public static implicit operator System.Drawing.Color(RGBQUAD c) => c.Color; } }