Click or drag to resize
Accord.NET (logo)

RGB Structure

RGB components.

Namespace:  Accord.Imaging
Assembly:  Accord.Imaging (in Accord.Imaging.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public struct RGB
Request Example View Source

The RGB type exposes the following members.

Constructors
  NameDescription
Public methodRGB(Color)
Initializes a new instance of the RGB class.
Public methodRGB(Byte, Byte, Byte)
Initializes a new instance of the RGB class.
Public methodRGB(Byte, Byte, Byte, Byte)
Initializes a new instance of the RGB class.
Top
Properties
  NameDescription
Public propertyColor
Color value of the class.
Top
Methods
  NameDescription
Public methodEquals
Indicates whether this instance and a specified object are equal.
(Inherited from ValueType.)
Public methodGetHashCode
Returns the hash code for this instance.
(Inherited from ValueType.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns the fully qualified type name of this instance.
(Inherited from ValueType.)
Top
Operators
Fields
  NameDescription
Public fieldStatic memberA
Index of alpha component for ARGB images.
Public fieldAlpha
Alpha component.
Public fieldStatic memberB
Index of blue component.
Public fieldBlue
Blue component.
Public fieldStatic memberG
Index of green component.
Public fieldGreen
Green component.
Public fieldStatic memberR
Index of red component.
Public fieldRed
Red component.
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

The class encapsulates RGB color components and can be used to implement logic for reading, writing and converting to and from RGB color representations.

Note Note
The PixelFormat.Format24bppRgb actually refers to a BGR pixel format.

Examples

The following examples show how to convert to and from various pixel representations:

// This example shows how to convert to and from various
// pixel representations. For example, let's say we start
// with a RGB pixel with the value (24, 250, 153):
RGB rgb = new RGB(red: 24, green: 250, blue: 153);

// The value of this pixel in HSL format would be:
HSL hsl = HSL.FromRGB(rgb);       // should be (154, 0.9576271, 0.5372549)

// The value of this pixel in YCbCr format would be:
YCbCr yCbCr = YCbCr.FromRGB(rgb); // should be (0.671929836, -0.0406815559, -0.412097245)

// Note: we can also convert using casting:
HSL a = (HSL)rgb;
YCbCr b = (YCbCr)rgb;
// This example shows how to convert to and from various
// pixel representations. For example, let's say we start
// with a HSL pixel with the value (123, 0.4, 0.8):
HSL hsl = new HSL(hue: 123, saturation: 0.4f, luminance: 0.8f);

// The value of this pixel in RGB format would be:
RGB rgb = hsl.ToRGB();       // should be (183, 224, 185)

// The value of this pixel in YCbCr format would be:
YCbCr yCbCr = YCbCr.FromRGB(rgb); // should be (0.8128612, -0.0493462719, -0.0679121539)

// Note: we can also convert using casting:
RGB a = (RGB)hsl;
YCbCr b = (YCbCr)hsl;
// This example shows how to convert to and from various
// pixel representations. For example, let's say we start
// with a YCbCr pixel with the value (0.8, 0.2, 0.5):
YCbCr yCbCr = new YCbCr(y: 0.8f, cb: 0.2f, cr: 0.5f);

// The value of this pixel in RGB format would be:
RGB rgb = yCbCr.ToRGB();  // should be (255, 95, 255)

// The value of this pixel in HSL format would be:
HSL hsl = HSL.FromRGB(rgb); // should be (299, 0.99999994, 0.6862745)

// Note: we can also convert using casting:
RGB a = (RGB)yCbCr;
HSL b = (HSL)yCbCr;
See Also