Xamarin Skiasharp Skpaint SkTypeface null

Seth Isaacks 51 Reputation points
2023-02-17T02:06:36.68+00:00

I have an xamarin forms application.

I am using Skiasharp for drawing.

I am trying too import a font and I cannot get the Typeface to set.

I have followed the online guide, I am not sure what I am doing wrong.

The ttf file is an embedded resource

Please see the code below:

public static SKPaint SelectedText => new SKPaint { Color = SKColors.Black, FakeBoldText = true, Style = SKPaintStyle.Stroke, StrokeWidth = .6f };

private static SKTypeface GetFont()
{
            SKTypeface sKTypeface = null;

            using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyApp.Resources.Fonts.Roboto-Regular.ttf"))
            {
                SKTypeface result = SKTypeface.FromStream(resource);
            }

            return sKTypeface;
}

// even though the resource is found and returned, TypeFace is still null.  Why? What am I doing wrong?
SelectedWidgetText.Typeface = GetFont();
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,377 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,103 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.