SkiaSharp.SKPaint Class

Holds the style and color information about how to draw geometries, text and bitmaps.

See Also: SKPaint

Syntax

public class SKPaint : SKObject

Remarks

Anytime you draw something in SkiaSharp, and want to specify what color it is, or how it blends with the background, or what style or font to draw it in, you specify those attributes in a paint.

Unlike SKCanvas, an SKPaint object do not maintain an internal stack of state.   That is, there is no save/restore on a paint. However, SKPaint objects are relatively light-weight, so the client may create and maintain any number of paint objects, each set up for a particular use. 

Factoring all of these color and stylistic attributes out of the canvas state, and into (multiple) paint objects, allows the save and restore operations on the SKCanvas to be that much more efficient, as all they have to do is maintain the stack of matrix and clip settings.

The example above produces the following:

This shows three different paints, each set up to draw in a different style. Now the caller can intermix these paints freely, either using them as is, or modifying them as the drawing proceeds.

Beyond simple attributes such as color, strokes, and text values, paints support effects. These are subclasses of different aspects of the drawing pipeline, that when referenced by a paint (each of them is reference-counted), are called to override some part of the drawing pipeline.

For example, to draw using a gradient instead of a single color, assign a SkShader to the paint.

Now, anything drawn with that paint will be drawn with the gradient specified in the call to CreateLinearGradient.

There are five types of effects that can be assigned to an SKPaint object:

  • BlendMode - Blend modes and Duff-Porter transfer modes.
  • ColorFilter - Modifies the source colors before applying the BlendMode.
  • MaskFilter - Modification of the alpha mask before it is colorized and drawn (for example, blur)
  • PathEffect - Modification of the geometry (path) before the alpha mask is generated (for example, dashing)
  • Shader - Gradients and bitmap patterns.

Requirements

Namespace: SkiaSharp
Assembly: SkiaSharp (in SkiaSharp.dll)
Assembly Versions: 1.0.0.0, 1.49.0.0, 1.52.0.0, 1.53.0.0, 1.54.0.0, 1.54.0.0, 1.55.0.0, 1.56.0.0, 1.57.0.0, 1.58.0.0, 1.59.0.0

The members of SkiaSharp.SKPaint are listed below.

See Also: SKObject

Public Constructors

Creates a new paint with the default settings.

Public Properties

BlendModeSKBlendMode. Gets or sets the blend mode.
ColorSKColor. Gets or sets the paint’s foreground color.
ColorFilterSKColorFilter. Gets or sets the paint’s color filter.
DeviceKerningEnabledBoolean. Gets or sets a value indicating whether device kerning is enabled.
FakeBoldTextBoolean. Gets or sets a value indicating whether fake bold text is enabled.
FilterQualitySKFilterQuality. Gets or sets the filter quality of the current paint.
[read-only]
FontMetricsSKFontMetrics. Gets the font metrics for the current typeface.
[read-only]
FontSpacingSingle. Gets the recommend line spacing.
HintingLevelSKPaintHinting. Gets or sets the level of hinting to be performed.
ImageFilterSKImageFilter. Gets or sets the image filter.
IsAntialiasBoolean. Gets or sets a value indicating whether anti-aliasing is enabled.
IsAutohintedBoolean. Gets or sets a value indicating whether auto-hinting is enabled.
IsDitherBoolean. Gets or sets a value indicating whether dithering is enabled.
IsEmbeddedBitmapTextBoolean. Gets or sets a value indicating whether text is an embedded bitmap.
IsLinearTextBoolean. Gets or sets a value indicating whether text is linear.
IsStrokeBoolean. Gets or sets a value indicating whether to paint a stroke or the fill.
IsVerticalTextBoolean. Gets or sets a value indicating whether the text is vertical or horizontal is enabled.
LcdRenderTextBoolean. Gets or sets a value indicating whether LCD text rendering is enabled.
MaskFilterSKMaskFilter. Gets or sets the mask filter to use when painting.
PathEffectSKPathEffect. Gets or sets the path effect to use when painting.
ShaderSKShader. Gets or sets the shader to use when painting.
StrikeThruTextBoolean. Gets or sets a value indicating whether to strike through text.
StrokeCapSKStrokeCap. Gets or sets a value indicating how the start and end of stroked lines and paths are treated.
StrokeJoinSKStrokeJoin. Gets or sets the path’s join type.
StrokeMiterSingle. Gets or sets the paint’s miter limit.
StrokeWidthSingle. Gets or sets the paint’s stroke width.
StyleSKPaintStyle. Gets or sets the painting style.
SubpixelTextBoolean. Gets or sets a value indicating whether to use subpixel text positioning.
TextAlignSKTextAlign. Gets or sets the path’s align value.
TextEncodingSKTextEncoding. Gets or sets the encoding used when drawing or measuring text.
TextScaleXSingle. Gets or sets paint’s horizontal scale factor for text.
TextSizeSingle. Gets or sets the text size.
TextSkewXSingle. Gets or sets paint’s horizontal skew factor for text.
TypefaceSKTypeface. Gets or sets the typeface used when painting text. May be null.
UnderlineTextBoolean. Gets or sets a value indicating whether to underline text.
XferModeSKXferMode. Gets or sets the transfer mode.

Public Methods

BreakText(String, Single) : Int64
Measure the text, stopping early if the measured width exceeds maxWidth.
BreakText(Byte[], Single, out Single) : Int64
Measure the text, stopping early if the measured width exceeds maxWidth.
BreakText(String, Single, out Single) : Int64
Measure the text, stopping early if the measured width exceeds maxWidth.
BreakText(IntPtr, IntPtr, Single, out Single) : Int64
Measure the text encoded as a UTF-8 buffer, stopping early if the measured width exceeds maxWidth.
Clone() : SKPaint
Creates a copy of the current paint.
GetFillPath(SKPath, SKPath, Single) : Boolean
Applies any and all effects to a source path, returning the result in the destination.
GetFillPath(SKPath, SKPath, SKRect, Single) : Boolean
Applies any and all effects to a source path, returning the result in the destination.
GetFontMetrics(out SKFontMetrics, Single) : Single
Returns the font metrics and line spacing for the current typeface.
GetTextPath(Byte[], SKPoint[]) : SKPath
Returns the path (outline) for the specified text.
GetTextPath(String, SKPoint[]) : SKPath
Returns the path (outline) for the specified text.
GetTextPath(Byte[], Single, Single) : SKPath
Returns the path (outline) for the specified text.
GetTextPath(IntPtr, IntPtr, SKPoint[]) : SKPath
Returns the path (outline) for the specified text.
GetTextPath(String, Single, Single) : SKPath
Returns the path (outline) for the specified text.
GetTextPath(IntPtr, IntPtr, Single, Single) : SKPath
Returns the path (outline) for the specified text.
MeasureText(Byte[]) : Single
Measures the specified text.
MeasureText(String) : Single
Measures the specified text.
MeasureText(Byte[], ref SKRect) : Single
Measures the specified text.
MeasureText(IntPtr, IntPtr) : Single
Measures the specified UTF-8 encoded text.
MeasureText(String, ref SKRect) : Single
Measures the specified text.
MeasureText(IntPtr, IntPtr, ref SKRect) : Single
Measures the specified UTF-8 encoded text.

Protected Methods

override
Dispose(Boolean)