Class PixColor
Inheritance
System.Object
PixColor
Assembly: IronOcr.dll
Syntax
public sealed class PixColor : ValueType
A single RGBA color in Leptonica's pixel model is held by PixColor. It is the color value used across the low-level image layer, the entries of a PixColormap, the channels of a pixel, and the colors compared when selecting or replacing regions of an image. Working with it directly is rarely needed for ordinary text OCR, but it is the type that appears when code inspects or edits the colors of an image before recognition.
A PixColor is created from its four channel bytes with new PixColor(red, green, blue, alpha), or built from a packed integer through the static FromRgb and FromRgba factories. It is a value type, so copies are independent and two colors compare by value through Equals and the == and != operators. Explicit conversion operators bridge to and from IronSoftware.Drawing.Color, so a PixColor can be turned into the shared drawing color the rest of the library uses, and back again.
The four channel properties, Red, Green, Blue, and Alpha, expose the components for reading or matching, and ToRGBA packs them back into a single integer for APIs that expect the combined form. Because the struct is immutable in practice, construct a new value rather than mutating an existing one when a different color is needed. Pass a PixColor to a PixColormap to add or test palette entries when adjusting an image's colors.
using DynamicTesseract;
using IronSoftware.Drawing;
var black = new PixColor(0, 0, 0, 255);
PixColor fromPacked = PixColor.FromRgba(0xFF0000FF);
Color shared = (Color)black;
The replace color example edits image colors before OCR, the select text by color example matches colors, and the image color correction how-to covers color cleanup.
Constructors
PixColor(Byte, Byte, Byte, Byte)
Declaration
public PixColor(byte red, byte green, byte blue, byte alpha = 255)
Parameters
| Type |
Name |
Description |
| System.Byte |
red |
|
| System.Byte |
green |
|
| System.Byte |
blue |
|
| System.Byte |
alpha |
|
Properties
Alpha
Declaration
public byte Alpha { get; }
Property Value
| Type |
Description |
| System.Byte |
|
Blue
Declaration
public byte Blue { get; }
Property Value
| Type |
Description |
| System.Byte |
|
Green
Declaration
public byte Green { get; }
Property Value
| Type |
Description |
| System.Byte |
|
Red
Declaration
Property Value
| Type |
Description |
| System.Byte |
|
Methods
Equals(PixColor)
Declaration
public bool Equals(PixColor other)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
| Type |
Name |
Description |
| System.Object |
obj |
|
Returns
| Type |
Description |
| System.Boolean |
|
FromRgb(UInt32)
Declaration
public static PixColor FromRgb(uint value)
Parameters
| Type |
Name |
Description |
| System.UInt32 |
value |
|
Returns
FromRgba(UInt32)
Declaration
public static PixColor FromRgba(uint value)
Parameters
| Type |
Name |
Description |
| System.UInt32 |
value |
|
Returns
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type |
Description |
| System.Int32 |
|
ToRGBA()
Declaration
Returns
| Type |
Description |
| System.UInt32 |
|
ToString()
Declaration
public override string ToString()
Returns
| Type |
Description |
| System.String |
|
Operators
Equality(PixColor, PixColor)
Declaration
public static bool operator ==(PixColor lhs, PixColor rhs)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
Explicit(PixColor to Color)
Declaration
public static explicit operator Color(PixColor color)
Parameters
Returns
| Type |
Description |
| IronSoftware.Drawing.Color |
|
Explicit(Color to PixColor)
Declaration
public static explicit operator PixColor(Color color)
Parameters
| Type |
Name |
Description |
| IronSoftware.Drawing.Color |
color |
|
Returns
Inequality(PixColor, PixColor)
Declaration
public static bool operator !=(PixColor lhs, PixColor rhs)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
Implements
System.IEquatable<>