Table of Contents

Class BitmapFont<T>

Namespace
AiDotNet.ComputerVision.Visualization
Assembly
AiDotNet.dll

A simple 5x7 bitmap font for rendering text on images.

public class BitmapFont<T>

Type Parameters

T

The numeric type used for calculations.

Inheritance
BitmapFont<T>
Inherited Members

Remarks

For Beginners: This class provides a way to draw text on images without requiring external font libraries. Each character is defined as a 5-wide by 7-tall grid of pixels.

Constructors

BitmapFont()

Creates a new bitmap font instance.

public BitmapFont()

Fields

CharHeight

Character height in pixels.

public const int CharHeight = 7

Field Value

int

CharSpacing

Horizontal spacing between characters.

public const int CharSpacing = 1

Field Value

int

CharWidth

Character width in pixels.

public const int CharWidth = 5

Field Value

int

Methods

DrawText(Tensor<T>, string, int, int, (double R, double G, double B), int)

Draws text on an image at the specified position.

public void DrawText(Tensor<T> image, string text, int x, int y, (double R, double G, double B) color, int scale = 1)

Parameters

image Tensor<T>

The image tensor [batch, channels, height, width].

text string

The text to draw.

x int

X position (left edge).

y int

Y position (top edge).

color (double X, double Y, double Z)

Text color as RGB values (0-1 range).

scale int

Scale factor (1 = original 5x7 size).

DrawTextWithBackground(Tensor<T>, string, int, int, (double R, double G, double B), (double R, double G, double B), int, int)

Draws text with a background box.

public void DrawTextWithBackground(Tensor<T> image, string text, int x, int y, (double R, double G, double B) textColor, (double R, double G, double B) bgColor, int scale = 1, int padding = 2)

Parameters

image Tensor<T>

The image tensor.

text string

The text to draw.

x int

X position.

y int

Y position.

textColor (double X, double Y, double Z)

Text color (0-1 range).

bgColor (double X, double Y, double Z)

Background color (0-1 range).

scale int

Scale factor.

padding int

Padding around text in pixels.

MeasureWidth(string)

Measures the width of a text string in pixels.

public int MeasureWidth(string text)

Parameters

text string

The text to measure.

Returns

int

Width in pixels.