SKCanvas.DrawText Method

Definition

Overloads

DrawText(IntPtr, Int32, SKPath, Single, Single, SKPaint)

Draws text encoded in a UTF-8 buffer on the canvas following a path.

DrawText(String, SKPath, Single, Single, SKPaint)

Draws text on the canvas following a path.

DrawText(IntPtr, Int32, Single, Single, SKPaint)

Draws text encoded in a UTF-8 buffer on the canvas at the specified coordinates.

DrawText(Byte[], SKPath, Single, Single, SKPaint)

Draws text on the canvas following a path.

DrawText(IntPtr, Int32, SKPoint[], SKPaint)

Draws text from a UTF-8 buffer at specified locations on the canvas.

DrawText(String, Single, Single, SKPaint)

Draws text on the canvas at the specified coordinates.

DrawText(Byte[], Single, Single, SKPaint)

Draws text on the canvas at the specified coordinates.

DrawText(SKTextBlob, Single, Single, SKPaint)

Draws a text blob on the canvas at the specified coordinates.

DrawText(String, SKPoint[], SKPaint)

Draws glyphs of the text at specified locations on the canvas.

DrawText(String, SKPoint, SKPaint)

Draws text on the canvas at the specified coordinates.

DrawText(Byte[], SKPoint, SKPaint)

Draws text on the canvas at the specified coordinates.

DrawText(IntPtr, Int32, SKPoint, SKPaint)

Draws text encoded in a UTF-8 buffer on the canvas at the specified coordinates.

Examples

var info = new SKImageInfo(512, 256);
using (var surface = SKSurface.Create(info)) {
    SKCanvas canvas = surface.Canvas;

    canvas.Clear(SKColors.White);

    // draw left-aligned text, solid
    using (var paint = new SKPaint()) {
        paint.TextSize = 64.0f;
        paint.IsAntialias = true;
        paint.Color = new SKColor(0x42, 0x81, 0xA4);
        paint.IsStroke = false;

        canvas.DrawText("Skia", info.Width / 2f, 64.0f, paint);
    }

    // draw centered text, stroked
    using (var paint = new SKPaint()) {
        paint.TextSize = 64.0f;
        paint.IsAntialias = true;
        paint.Color = new SKColor(0x9C, 0xAF, 0xB7);
        paint.IsStroke = true;
        paint.StrokeWidth = 3;
        paint.TextAlign = SKTextAlign.Center;

        canvas.DrawText("Skia", info.Width / 2f, 144.0f, paint);
    }

    // draw right-aligned text, scaled
    using (var paint = new SKPaint()) {
        paint.TextSize = 64.0f;
        paint.IsAntialias = true;
        paint.Color = new SKColor(0xE6, 0xB8, 0x9C);
        paint.TextScaleX = 1.5f;
        paint.TextAlign = SKTextAlign.Right;

        canvas.DrawText("Skia", info.Width / 2f, 224.0f, paint);
    }
}

The example above produces the following:

SKCanvas, SKPaint and DrawText

DrawText(IntPtr, Int32, SKPath, Single, Single, SKPaint)

Warning

This API is now obsolete.

Draws text encoded in a UTF-8 buffer on the canvas following a path.

[System.Obsolete("Use DrawTextOnPath instead.", true)]
public void DrawText (IntPtr buffer, int length, SkiaSharp.SKPath path, float hOffset, float vOffset, SkiaSharp.SKPaint paint);

Parameters

buffer
IntPtr

The pointer to a region holding UTF-8 encoded text to draw.

length
Int32

The number of bytes to read from the buffer.

path
SKPath

The path the text should follow for its baseline.

hOffset
Single

The distance along the path to add to the text's starting position.

vOffset
Single

The distance above (-) or below (+) the path to position the text.

paint
SKPaint

The paint to use when drawing the text.

Attributes

DrawText(String, SKPath, Single, Single, SKPaint)

Warning

This API is now obsolete.

Draws text on the canvas following a path.

[System.Obsolete("Use DrawTextOnPath instead.", true)]
public void DrawText (string text, SkiaSharp.SKPath path, float hOffset, float vOffset, SkiaSharp.SKPaint paint);

Parameters

text
String

The text to draw.

path
SKPath

The path the text should follow for its baseline.

hOffset
Single

The distance along the path to add to the text's starting position.

vOffset
Single

The distance above (-) or below (+) the path to position the text.

paint
SKPaint

The paint to use when drawing the text.

Attributes

DrawText(IntPtr, Int32, Single, Single, SKPaint)

Draws text encoded in a UTF-8 buffer on the canvas at the specified coordinates.

public void DrawText (IntPtr buffer, int length, float x, float y, SkiaSharp.SKPaint paint);

Parameters

buffer
IntPtr

The pointer to a region holding UTF-8 encoded text to draw.

length
Int32

The number of bytes to read from the buffer.

x
Single

The x-coordinate of the origin of the text being drawn.

y
Single

The y-coordinate of the origin of the text being drawn.

paint
SKPaint

The paint to use when drawing the text.

DrawText(Byte[], SKPath, Single, Single, SKPaint)

Warning

This API is now obsolete.

Draws text on the canvas following a path.

[System.Obsolete("Use DrawTextOnPath instead.", true)]
public void DrawText (byte[] text, SkiaSharp.SKPath path, float hOffset, float vOffset, SkiaSharp.SKPaint paint);

Parameters

text
Byte[]

The text to draw.

path
SKPath

The path the text should follow for its baseline.

hOffset
Single

The distance along the path to add to the text's starting position.

vOffset
Single

The distance above (-) or below (+) the path to position the text.

paint
SKPaint

The paint to use when drawing the text.

Attributes

DrawText(IntPtr, Int32, SKPoint[], SKPaint)

Warning

This API is now obsolete.

Draws text from a UTF-8 buffer at specified locations on the canvas.

[System.Obsolete("Use DrawPositionedText instead.", true)]
public void DrawText (IntPtr buffer, int length, SkiaSharp.SKPoint[] points, SkiaSharp.SKPaint paint);

Parameters

buffer
IntPtr

The pointer to a region holding UTF-8 encoded text to draw.

length
Int32

The number of bytes to read from the buffer.

points
SKPoint[]

The positions for each glyph in the buffer.

paint
SKPaint

The paint to use when drawing the text.

Attributes

DrawText(String, Single, Single, SKPaint)

Draws text on the canvas at the specified coordinates.

public void DrawText (string text, float x, float y, SkiaSharp.SKPaint paint);

Parameters

text
String

The text to draw.

x
Single

The x-coordinate of the origin of the text being drawn.

y
Single

The y-coordinate of the origin of the text being drawn.

paint
SKPaint

The paint to use when drawing the text.

DrawText(Byte[], Single, Single, SKPaint)

Draws text on the canvas at the specified coordinates.

public void DrawText (byte[] text, float x, float y, SkiaSharp.SKPaint paint);

Parameters

text
Byte[]

The text to draw.

x
Single

The x-coordinate of the origin of the text being drawn.

y
Single

The y-coordinate of the origin of the text being drawn.

paint
SKPaint

The paint to use when drawing the text.

DrawText(SKTextBlob, Single, Single, SKPaint)

Draws a text blob on the canvas at the specified coordinates.

public void DrawText (SkiaSharp.SKTextBlob text, float x, float y, SkiaSharp.SKPaint paint);

Parameters

text
SKTextBlob

The text blob to draw.

x
Single

The x-coordinate of the origin of the text being drawn.

y
Single

The y-coordinate of the origin of the text being drawn.

paint
SKPaint

The paint to use when drawing the text.

DrawText(String, SKPoint[], SKPaint)

Warning

This API is now obsolete.

Draws glyphs of the text at specified locations on the canvas.

[System.Obsolete("Use DrawPositionedText instead.", true)]
public void DrawText (string text, SkiaSharp.SKPoint[] points, SkiaSharp.SKPaint paint);

Parameters

text
String

The text to draw.

points
SKPoint[]

The positions for each glyph in the text string.

paint
SKPaint

The paint to use when drawing the text.

Attributes

DrawText(String, SKPoint, SKPaint)

Draws text on the canvas at the specified coordinates.

public void DrawText (string text, SkiaSharp.SKPoint p, SkiaSharp.SKPaint paint);

Parameters

text
String

The text to draw.

p
SKPoint

The coordinates of the origin of the text being drawn.

paint
SKPaint

The paint to use when drawing the text.

DrawText(Byte[], SKPoint, SKPaint)

Draws text on the canvas at the specified coordinates.

public void DrawText (byte[] text, SkiaSharp.SKPoint p, SkiaSharp.SKPaint paint);

Parameters

text
Byte[]

The text to draw.

p
SKPoint

The coordinates of the origin of the text being drawn.

paint
SKPaint

The paint to use when drawing the text.

DrawText(IntPtr, Int32, SKPoint, SKPaint)

Draws text encoded in a UTF-8 buffer on the canvas at the specified coordinates.

public void DrawText (IntPtr buffer, int length, SkiaSharp.SKPoint p, SkiaSharp.SKPaint paint);

Parameters

buffer
IntPtr

The pointer to a region holding UTF-8 encoded text to draw.

length
Int32

The number of bytes to read from the buffer.

p
SKPoint

The coordinates of the origin of the text being drawn.

paint
SKPaint

The paint to use when drawing the text.

Applies to