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
TThe 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
CharSpacing
Horizontal spacing between characters.
public const int CharSpacing = 1
Field Value
CharWidth
Character width in pixels.
public const int CharWidth = 5
Field Value
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
imageTensor<T>The image tensor [batch, channels, height, width].
textstringThe text to draw.
xintX position (left edge).
yintY position (top edge).
color(double X, double Y, double Z)Text color as RGB values (0-1 range).
scaleintScale 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
imageTensor<T>The image tensor.
textstringThe text to draw.
xintX position.
yintY 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).
scaleintScale factor.
paddingintPadding around text in pixels.
MeasureWidth(string)
Measures the width of a text string in pixels.
public int MeasureWidth(string text)
Parameters
textstringThe text to measure.
Returns
- int
Width in pixels.