Class PixColormap
Inheritance
System.Object
PixColormap
Implements
System.IDisposable
Assembly: IronOcr.dll
Syntax
public sealed class PixColormap : Object
PixColormap manages the palette of a colormapped Leptonica image, the indexed table that maps each pixel value to an actual PixColor. It is the type code works through when an image stores colors by index rather than per pixel, for example a quantized scan whose palette must be inspected or edited before recognition. Most text OCR never touches it, but color cleanup and image-preparation steps do.
A colormap is created through the static factories rather than a constructor: Create allocates an empty map of a given bit depth, while the two CreateLinear overloads build a ready-made grayscale ramp. Because the type holds a native handle and implements IDisposable, dispose it (or use using) once editing is finished. Count reports how many colors the map currently holds, FreeCount how many slots remain, and Depth the bit depth that bounds its capacity.
Colors are added and queried through the palette methods. AddColor appends a PixColor, AddNewColor adds one only if it is not already present and returns its index, and AddNearestColor maps a requested color to the closest existing entry. AddBlackOrWhite and SetBlackOrWhite manage the black and white endpoints, IsUsableColor tests whether a color can be added within the depth limit, and the Item indexer reads an entry by position. Clear empties the map for reuse. Build each entry from a PixColor, the RGBA color this table indexes.
using DynamicTesseract;
using PixColormap map = PixColormap.Create(8);
map.AddColor(new PixColor(0, 0, 0, 255));
map.AddNewColor(new PixColor(255, 255, 255, 255), out int whiteIndex);
The replace color example edits image colors before OCR, the image color correction how-to covers color cleanup, and the select text by color example matches palette colors.
Properties
Count
Declaration
public int Count { get; }
Property Value
| Type |
Description |
| System.Int32 |
|
Depth
Declaration
public int Depth { get; }
Property Value
| Type |
Description |
| System.Int32 |
|
FreeCount
Declaration
public int FreeCount { get; }
Property Value
| Type |
Description |
| System.Int32 |
|
Item[Int32]
Declaration
public PixColor this[int index] { get; set; }
Parameters
| Type |
Name |
Description |
| System.Int32 |
index |
|
Property Value
Methods
AddBlackOrWhite(Int32, out Int32)
Declaration
public bool AddBlackOrWhite(int color, out int index)
Parameters
| Type |
Name |
Description |
| System.Int32 |
color |
|
| System.Int32 |
index |
|
Returns
| Type |
Description |
| System.Boolean |
|
AddColor(PixColor)
Declaration
public bool AddColor(PixColor color)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
AddNearestColor(PixColor, out Int32)
Declaration
public bool AddNearestColor(PixColor color, out int index)
Parameters
| Type |
Name |
Description |
| PixColor |
color |
|
| System.Int32 |
index |
|
Returns
| Type |
Description |
| System.Boolean |
|
AddNewColor(PixColor, out Int32)
Declaration
public bool AddNewColor(PixColor color, out int index)
Parameters
| Type |
Name |
Description |
| PixColor |
color |
|
| System.Int32 |
index |
|
Returns
| Type |
Description |
| System.Boolean |
|
Clear()
Declaration
Create(Int32)
Declaration
public static PixColormap Create(int depth)
Parameters
| Type |
Name |
Description |
| System.Int32 |
depth |
|
Returns
CreateLinear(Int32, Boolean, Boolean)
Declaration
public static PixColormap CreateLinear(int depth, bool firstIsBlack, bool lastIsWhite)
Parameters
| Type |
Name |
Description |
| System.Int32 |
depth |
|
| System.Boolean |
firstIsBlack |
|
| System.Boolean |
lastIsWhite |
|
Returns
CreateLinear(Int32, Int32)
Declaration
public static PixColormap CreateLinear(int depth, int levels)
Parameters
| Type |
Name |
Description |
| System.Int32 |
depth |
|
| System.Int32 |
levels |
|
Returns
Dispose()
Declaration
IsUsableColor(PixColor)
Declaration
public bool IsUsableColor(PixColor color)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
SetBlackOrWhite(Boolean, Boolean)
Declaration
public bool SetBlackOrWhite(bool setBlack, bool setWhite)
Parameters
| Type |
Name |
Description |
| System.Boolean |
setBlack |
|
| System.Boolean |
setWhite |
|
Returns
| Type |
Description |
| System.Boolean |
|
Implements
System.IDisposable