상속: SKStreamAsset
예제 #1
0
        public static SKStreamAsset OpenStream(string path)
        {
            var stream = new SKFileStream(path);

            if (!stream.IsValid)
            {
                stream.Dispose();
                stream = null;
            }
            return(stream);
        }
예제 #2
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);
                        }
            }
        }
예제 #3
0
 private static SKStream OpenStream(string path)
 {
     if (!SKFileStream.IsPathSupported(path))
     {
         // due to a bug (https://github.com/mono/SkiaSharp/issues/390)
         return(WrapManagedStream(File.OpenRead(path)));
     }
     else
     {
         return(new SKFileStream(path));
     }
 }
예제 #4
0
        public static SKCodec Create(string filename, out SKCodecResult result)
        {
            var stream = SKFileStream.OpenStream(filename);

            if (stream == null)
            {
                result = SKCodecResult.InternalError;
                return(null);
            }

            return(Create(stream, out result));
        }
예제 #5
0
 public static SKTypeface FromFile(string path, int index = 0)
 {
     if (path == null)
     {
         throw new ArgumentNullException(nameof(path));
     }
     using (var stream = SKFileStream.OpenStream(path)) {
         if (stream == null)
         {
             return(null);
         }
         else
         {
             return(FromStream(stream, index));
         }
     }
 }
예제 #6
0
        public static SKData Create(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentException("The filename cannot be empty.", nameof(filename));
            }

            using (var stream = SKFileStream.OpenStream(filename)) {
                if (stream == null)
                {
                    return(null);
                }
                else
                {
                    return(Create(stream));
                }
            }
        }
예제 #7
0
 public static bool IsPathSupported(string path) => SKFileStream.IsPathSupported(path);
		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 = 40;
					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 = 40;
					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 = 40;
						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 = 40;
					paint.Typeface = tf;

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