Table of Contents

Class SkiaImage

Namespace
DrawnUi.Draw
Assembly
DrawnUi.Maui.dll
public class SkiaImage : SkiaControl, INotifyPropertyChanged, IEffectControlProvider, IToolTipElement, IContextFlyoutElement, IAnimatable, IVisualElementController, IElementController, IView, ITransform, IElement, IVisualTreeElement, IContainer, IList<IView>, ICollection<IView>, IEnumerable<IView>, IEnumerable, ISkiaGestureListener, IHasAfterEffects, ISkiaControl, IDrawnBase, ICanBeUpdatedWithContext, ICanBeUpdated, ISkiaDisposable, IDisposable
Inheritance
SkiaImage
Implements
Derived
Inherited Members
Extension Methods

Constructors

SkiaImage()

public SkiaImage()

SkiaImage(string)

public SkiaImage(string source)

Parameters

source string

Fields

AddEffectProperty

public static readonly BindableProperty AddEffectProperty

Field Value

BindableProperty

AspectProperty

public static readonly BindableProperty AspectProperty

Field Value

BindableProperty

BlurProperty

public static readonly BindableProperty BlurProperty

Field Value

BindableProperty

BrightnessProperty

public static readonly BindableProperty BrightnessProperty

Field Value

BindableProperty

CacheRescaledSourceProperty

public static readonly BindableProperty CacheRescaledSourceProperty

Field Value

BindableProperty

CancelLoading

public CancellationTokenSource CancelLoading

Field Value

CancellationTokenSource

ClipSource

public bool ClipSource

Field Value

bool

ColorTintProperty

public static readonly BindableProperty ColorTintProperty

Field Value

BindableProperty

ContrastProperty

public static readonly BindableProperty ContrastProperty

Field Value

BindableProperty

DarkenProperty

public static readonly BindableProperty DarkenProperty

Field Value

BindableProperty

DrawWhenEmptyProperty

public static readonly BindableProperty DrawWhenEmptyProperty

Field Value

BindableProperty

EffectBlendModeProperty

public static readonly BindableProperty EffectBlendModeProperty

Field Value

BindableProperty

EndColorProperty

public static readonly BindableProperty EndColorProperty

Field Value

BindableProperty

EraseChangedContentProperty

public static readonly BindableProperty EraseChangedContentProperty

Field Value

BindableProperty

GammaProperty

public static readonly BindableProperty GammaProperty

Field Value

BindableProperty

HorizontalAlignmentProperty

public static readonly BindableProperty HorizontalAlignmentProperty

Field Value

BindableProperty

HorizontalOffsetProperty

public static readonly BindableProperty HorizontalOffsetProperty

Field Value

BindableProperty

ImageBitmapProperty

public static readonly BindableProperty ImageBitmapProperty

Field Value

BindableProperty

ImagePaint

Reusing this

protected SKPaint ImagePaint

Field Value

SKPaint

InflateAmountProperty

public static readonly BindableProperty InflateAmountProperty

Field Value

BindableProperty

LightenProperty

public static readonly BindableProperty LightenProperty

Field Value

BindableProperty

LoadSourceOnFirstDrawProperty

public static readonly BindableProperty LoadSourceOnFirstDrawProperty

Field Value

BindableProperty

LogEnabled

public static bool LogEnabled

Field Value

bool

PaintColorFilter

Reusing this

protected SKColorFilter PaintColorFilter

Field Value

SKColorFilter

PaintImageFilter

Reusing this

public SKImageFilter PaintImageFilter

Field Value

SKImageFilter

PreviewBase64Property

public static readonly BindableProperty PreviewBase64Property

Field Value

BindableProperty

RescaleSourceProperty

public static readonly BindableProperty RescaleSourceProperty

Field Value

BindableProperty

RescalingQualityProperty

public static readonly BindableProperty RescalingQualityProperty

Field Value

BindableProperty

SaturationProperty

public static readonly BindableProperty SaturationProperty

Field Value

BindableProperty

SourceProperty

public static readonly BindableProperty SourceProperty

Field Value

BindableProperty

SpriteHeightProperty

public static readonly BindableProperty SpriteHeightProperty

Field Value

BindableProperty

SpriteIndexProperty

public static readonly BindableProperty SpriteIndexProperty

Field Value

BindableProperty

SpriteWidthProperty

public static readonly BindableProperty SpriteWidthProperty

Field Value

BindableProperty

StartColorProperty

public static readonly BindableProperty StartColorProperty

Field Value

BindableProperty

UseAssemblyProperty

public static readonly BindableProperty UseAssemblyProperty

Field Value

BindableProperty

UseGradientProperty

public static readonly BindableProperty UseGradientProperty

Field Value

BindableProperty

VerticalAlignmentProperty

public static readonly BindableProperty VerticalAlignmentProperty

Field Value

BindableProperty

VerticalOffsetProperty

public static readonly BindableProperty VerticalOffsetProperty

Field Value

BindableProperty

ZoomXProperty

public static readonly BindableProperty ZoomXProperty

Field Value

BindableProperty

ZoomYProperty

public static readonly BindableProperty ZoomYProperty

Field Value

BindableProperty

Properties

AddEffect

public SkiaImageEffect AddEffect { get; set; }

Property Value

SkiaImageEffect

ApplyNewSource

protected LoadedImageSource ApplyNewSource { get; set; }

Property Value

LoadedImageSource

Aspect

Apspect to render image with, default is AspectCover.

public TransformAspect Aspect { get; set; }

Property Value

TransformAspect

AspectScale

public SKPoint AspectScale { get; protected set; }

Property Value

SKPoint

Blur

public double Blur { get; set; }

Property Value

double

Brightness

public double Brightness { get; set; }

Property Value

double

CacheRescaledSource

Defines if we should cached the rescaled source when RescalingQuality is set or apply the quality on every draw instead. Default is true. You might want to set this to false for very fast changing source, like camera/video feed etc.

public bool CacheRescaledSource { get; set; }

Property Value

bool

CachedImage

Provides a cached image if any

public override SKImage CachedImage { get; }

Property Value

SKImage

CanDraw

public override bool CanDraw { get; }

Property Value

bool

ColorTint

public Color ColorTint { get; set; }

Property Value

Color

Contrast

public double Contrast { get; set; }

Property Value

double

Darken

public double Darken { get; set; }

Property Value

double

DisplayRect

public SKRect DisplayRect { get; set; }

Property Value

SKRect

DrawWhenEmpty

public bool DrawWhenEmpty { get; set; }

Property Value

bool

EffectBlendMode

public SKBlendMode EffectBlendMode { get; set; }

Property Value

SKBlendMode

EndColor

public Color EndColor { get; set; }

Property Value

Color

EraseChangedContent

Should we erase the existing image when another Source is set but wasn't applied yet (not loaded yet)

public bool EraseChangedContent { get; set; }

Property Value

bool

Gamma

public double Gamma { get; set; }

Property Value

double

HasError

public bool HasError { get; protected set; }

Property Value

bool

HasUnstableSize

Set this to true for cases when your image is auto-sized and changing the source should re-measure it again.

public bool HasUnstableSize { get; set; }

Property Value

bool

HorizontalAlignment

public DrawImageAlignment HorizontalAlignment { get; set; }

Property Value

DrawImageAlignment

HorizontalOffset

public double HorizontalOffset { get; set; }

Property Value

double

ImageBitmap

this is the source loaded, doesn't reflect any effects or any other rendering properties

public LoadedImageSource ImageBitmap { get; set; }

Property Value

LoadedImageSource

ImageSource

public ImageSource ImageSource { get; protected set; }

Property Value

ImageSource

InflateAmount

public double InflateAmount { get; set; }

Property Value

double

IsLoading

public bool IsLoading { get; set; }

Property Value

bool

LastSource

Last source that we where loading. Td be reused for reload..

public ImageSource LastSource { get; protected set; }

Property Value

ImageSource

Lighten

public double Lighten { get; set; }

Property Value

double

LoadSource

public Action LoadSource { get; protected set; }

Property Value

Action

LoadSourceOnFirstDraw

Should the source be loaded on the first draw, useful for the first fast rendering of the screen and loading images after, default is False. Set this to False if you need an off-screen loading and to True to make the screen load faster. While images are loaded in async manner this still has its impact. Useful to set True for for SkiaCarousel cells etc..

public bool LoadSourceOnFirstDraw { get; set; }

Property Value

bool

LoadedSource

public LoadedImageSource LoadedSource { get; set; }

Property Value

LoadedImageSource

NeedInvalidateColorFilter

protected bool NeedInvalidateColorFilter { get; set; }

Property Value

bool

NeedInvalidateImageFilter

protected bool NeedInvalidateImageFilter { get; set; }

Property Value

bool

PreviewBase64

If setting in code-behind must be set BEFORE you change the Source

public string PreviewBase64 { get; set; }

Property Value

string

RescaleSource

Should rescale source if output viewport size changed and RescalingQuality>none. Default value is false.

public bool RescaleSource { get; set; }

Property Value

bool

RescalingQuality

Default value is Low.

public SKFilterQuality RescalingQuality { get; set; }

Property Value

SKFilterQuality

Saturation

public double Saturation { get; set; }

Property Value

double

ScaledSource

public SkiaImage.RescaledBitmap ScaledSource { get; protected set; }

Property Value

SkiaImage.RescaledBitmap

Source

[TypeConverter(typeof(FrameworkImageSourceConverter))]
public ImageSource Source { get; set; }

Property Value

ImageSource

SourceHeight

From current set Source in points

public float SourceHeight { get; protected set; }

Property Value

float

SourceImageSize

public ScaledRect SourceImageSize { get; protected set; }

Property Value

ScaledRect

SourceWidth

From current set Source in points

public float SourceWidth { get; protected set; }

Property Value

float

SpriteHeight

public double SpriteHeight { get; set; }

Property Value

double

SpriteIndex

public int SpriteIndex { get; set; }

Property Value

int

SpriteWidth

public double SpriteWidth { get; set; }

Property Value

double

StartColor

public Color StartColor { get; set; }

Property Value

Color

TextureScale

public SKPoint TextureScale { get; protected set; }

Property Value

SKPoint

UseAssembly

public object UseAssembly { get; set; }

Property Value

object

UseGradient

public bool UseGradient { get; set; }

Property Value

bool

VerticalAlignment

public DrawImageAlignment VerticalAlignment { get; set; }

Property Value

DrawImageAlignment

VerticalOffset

public double VerticalOffset { get; set; }

Property Value

double

ZoomX

public double ZoomX { get; set; }

Property Value

double

ZoomY

public double ZoomY { get; set; }

Property Value

double

Methods

AvoidRemeasuring(MeasureRequest)

public override bool AvoidRemeasuring(MeasureRequest request)

Parameters

request MeasureRequest

Returns

bool

CalculateDisplayRect(SKRect, float, float, DrawImageAlignment, DrawImageAlignment)

protected virtual SKRect CalculateDisplayRect(SKRect dest, float destWidth, float destHeight, DrawImageAlignment horizontal, DrawImageAlignment vertical)

Parameters

dest SKRect
destWidth float
destHeight float
horizontal DrawImageAlignment
vertical DrawImageAlignment

Returns

SKRect

ClearBitmap()

public virtual void ClearBitmap()

Draw(DrawingContext)

protected override void Draw(DrawingContext context)

Parameters

context DrawingContext

DrawSource(DrawingContext, LoadedImageSource, TransformAspect, DrawImageAlignment, DrawImageAlignment, SKPaint)

Updated DrawSource with professional-quality resizing

protected virtual void DrawSource(DrawingContext ctx, LoadedImageSource source, TransformAspect stretch, DrawImageAlignment horizontal = DrawImageAlignment.Center, DrawImageAlignment vertical = DrawImageAlignment.Center, SKPaint paint = null)

Parameters

ctx DrawingContext
source LoadedImageSource
stretch TransformAspect
horizontal DrawImageAlignment
vertical DrawImageAlignment
paint SKPaint

DrawSourceBitmap(DrawingContext, SKBitmap, SKRect, SKPaint, SKFilterQuality)

protected virtual void DrawSourceBitmap(DrawingContext ctx, SKBitmap bitmap, SKRect display, SKPaint paint, SKFilterQuality quality = SKFilterQuality.None)

Parameters

ctx DrawingContext
bitmap SKBitmap
display SKRect
paint SKPaint
quality SKFilterQuality

DrawSourceImage(DrawingContext, SKImage, SKRect, SKPaint, SKFilterQuality)

protected virtual void DrawSourceImage(DrawingContext ctx, SKImage image, SKRect display, SKPaint paint, SKFilterQuality quality = SKFilterQuality.None)

Parameters

ctx DrawingContext
image SKImage
display SKRect
paint SKPaint
quality SKFilterQuality

GetRenderedSource()

Will render on an off-screen surface and return result. Contains all the effects and other rendering properties applied, size will correspond to source.

public virtual SKImage GetRenderedSource()

Returns

SKImage

GetSamplingOptions(SKFilterQuality, bool)

Gets sampling options based on quality level

public static SKSamplingOptions GetSamplingOptions(SKFilterQuality quality, bool isUpscaling)

Parameters

quality SKFilterQuality

Quality level from user selection

isUpscaling bool

Whether the operation is upscaling

Returns

SKSamplingOptions

Appropriate SKSamplingOptions

Invalidate()

Base calls InvalidateInternal and InvalidateParent

public override void Invalidate()

InvalidateColorFilter()

public virtual void InvalidateColorFilter()

InvalidateImageFilter()

public virtual void InvalidateImageFilter()

LoadImageManagedAsync(ImageSource, CancellationTokenSource, LoadPriority)

protected virtual Task<SKBitmap> LoadImageManagedAsync(ImageSource source, CancellationTokenSource cancel, LoadPriority priority = LoadPriority.Normal)

Parameters

source ImageSource
cancel CancellationTokenSource
priority LoadPriority

Returns

Task<SKBitmap>

LoadSourceIfNeeded()

public virtual void LoadSourceIfNeeded()

OnDisposing()

Base performs some cleanup actions with Superview

public override void OnDisposing()

OnError(string)

public virtual void OnError(string source)

Parameters

source string

OnLayoutChanged()

DrawingRect size changed

protected override void OnLayoutChanged()

OnMeasuring(float, float, float)

Input in POINTS

public override ScaledSize OnMeasuring(float widthRequest, float heightRequest, float dscale)

Parameters

widthRequest float
heightRequest float
dscale float

Returns

ScaledSize

OnScaleChanged()

public override void OnScaleChanged()

OnSuccess(string)

public virtual void OnSuccess(string source)

Parameters

source string

OnWillDisposeWithChildren()

The OnDisposing might come with a delay to avoid disposing resources at use. This method will be called without delay when Dispose() is invoked. Disposed will set to True and for Views their OnWillDisposeWithChildren will be called.

public override void OnWillDisposeWithChildren()

Paint(DrawingContext)

This is the main drawing routine you should override to draw something. Base one paints background color inside DrawingRect that was defined by Arrange inside base.Draw. Pass arguments if you want to use some time-frozen data for painting at any time from any thread..

protected override void Paint(DrawingContext ctx)

Parameters

ctx DrawingContext

ReloadSource()

public virtual void ReloadSource()

SetAspectScale(int, int, SKRect, TransformAspect, float)

protected void SetAspectScale(int pxWidth, int pxHeight, SKRect dest, TransformAspect stretch, float scale)

Parameters

pxWidth int
pxHeight int
dest SKRect
stretch TransformAspect
scale float

SetBitmapInternal(SKBitmap, bool)

Use only if you know what to do, this internally just sets the new bitmap without any invalidations and not forcing an update. You would want to set InstancedBitmap prop for a usual approach.

public LoadedImageSource SetBitmapInternal(SKBitmap bitmap, bool protectFromDispose = false)

Parameters

bitmap SKBitmap
protectFromDispose bool

Returns

LoadedImageSource

SetFromBase64(string)

public void SetFromBase64(string input)

Parameters

input string

SetImage(LoadedImageSource)

Do not call this directly, use InstancedBitmap prop

protected virtual LoadedImageSource SetImage(LoadedImageSource loaded)

Parameters

loaded LoadedImageSource

Returns

LoadedImageSource

SetImageInternal(SKImage, bool)

public LoadedImageSource SetImageInternal(SKImage image, bool protectFromDispose = false)

Parameters

image SKImage
protectFromDispose bool

Returns

LoadedImageSource

SetImageSource(ImageSource)

public virtual void SetImageSource(ImageSource source)

Parameters

source ImageSource

SetMeasuredAsEmpty(float)

protected override ScaledSize SetMeasuredAsEmpty(float scale)

Parameters

scale float

Returns

ScaledSize

SetSource(ImageSource)

public void SetSource(ImageSource source)

Parameters

source ImageSource

SetSource(Func<CancellationToken, Task<Stream>>)

public void SetSource(Func<CancellationToken, Task<Stream>> getStream)

Parameters

getStream Func<CancellationToken, Task<Stream>>

SetSource(string)

public void SetSource(string source)

Parameters

source string

StopLoading()

public virtual void StopLoading()

SubscribeToCanReload()

protected virtual void SubscribeToCanReload()

SwapSources(float)

returns whether should abort pipeline

protected virtual bool SwapSources(float scale)

Parameters

scale float

Returns

bool

Events

Cleared

public event EventHandler Cleared

Event Type

EventHandler

DisplayRectChanged

public event EventHandler<SKRect> DisplayRectChanged

Event Type

EventHandler<SKRect>

Error

public event EventHandler<ContentLoadedEventArgs> Error

Event Type

EventHandler<ContentLoadedEventArgs>

Success

public event EventHandler<ContentLoadedEventArgs> Success

Event Type

EventHandler<ContentLoadedEventArgs>