FromStream() public static method

public static FromStream ( SKStreamAsset stream, int index ) : SKTypeface
stream SKStreamAsset
index int
return SKTypeface
コード例 #1
0
        public static void CustomFonts(SKCanvas canvas, int width, int height)
        {
            string text = "\u03A3 and \u0750";

            using (var paint = new SKPaint()) {
                canvas.Clear(SKColors.White);
                paint.IsAntialias = true;

                using (var tf = SKTypeface.FromFile(CustomFontPath)) {
                    paint.Color    = XamGreen;
                    paint.TextSize = 60;
                    paint.Typeface = tf;

                    canvas.DrawText(text, 50, 50, paint);
                }

                using (var stream = new SKFileStream(CustomFontPath))
                    using (var tf = SKTypeface.FromStream(stream)) {
                        paint.Color    = XamDkBlue;
                        paint.TextSize = 60;
                        paint.Typeface = tf;

                        canvas.DrawText(text, 50, 100, paint);
                    }

                var assembly = typeof(Demos).GetTypeInfo().Assembly;
                var fontName = assembly.GetName().Name + ".embedded-font.ttf";

                using (var resource = assembly.GetManifestResourceStream(fontName))
                    using (var memory = new MemoryStream()) {
                        resource.CopyTo(memory);
                        var bytes = memory.ToArray();
                        using (var stream = new SKMemoryStream(bytes))
                            using (var tf = SKTypeface.FromStream(stream)) {
                                paint.Color    = XamLtBlue;
                                paint.TextSize = 60;
                                paint.Typeface = tf;

                                canvas.DrawText(text, 50, 150, paint);
                            }
                    }

                using (var resource = assembly.GetManifestResourceStream(fontName))
                    using (var stream = new SKManagedStream(resource))
                        using (var tf = SKTypeface.FromStream(stream)) {
                            paint.Color    = XamPurple;
                            paint.TextSize = 60;
                            paint.Typeface = tf;

                            canvas.DrawText(text, 50, 200, paint);
                        }
            }
        }
コード例 #2
0
 public static SKTypeface FromData(SKData data, int index = 0)
 {
     return(SKTypeface.FromStream(new SKMemoryStream(data), index));
 }