Beispiel #1
0
 public static SvgImage GetCache(Assembly assembly, string imageName)
 {
     if (string.IsNullOrEmpty(imageName))
     {
         return(null);
     }
     if (!SvgCache.TryGetValue(imageName, out var svg))
     {
         var keyName = $"{assembly.GetName().Name}.Assets.{imageName}.svg";
         using (Stream stream = assembly.GetManifestResourceStream(keyName))
         {
             if (stream != null)
             {
                 svg = new SvgImage();
                 svg.Load(stream);
                 SvgCache[imageName] = svg;
             }
             else
             {
                 SvgCache[imageName] = null;
             }
         }
     }
     return(svg);
 }
Beispiel #2
0
        public static void DrawImage(SKCanvas canvas, SvgImage svg, SKPaint paint, SKRect bounds, float indent = 2)
        {
            var matrix = GetMatrix(svg, bounds, indent);

            canvas.Save();
            canvas.Concat(ref matrix);
            canvas.DrawPath(svg.Path, paint);
            canvas.Restore();
        }
Beispiel #3
0
        public static SKMatrix GetMatrix(SvgImage svg, float left, float top, float widthR, float heightR, float rotate = 0)
        {
            float canvasMin = Math.Min(widthR, heightR);
            // get the size of the picture
            float svgMax = Math.Max(svg.ViewBox.Width, svg.ViewBox.Height);
            // get the scale to fill the screen
            float scale  = canvasMin / svgMax;
            var   width  = svg.ViewBox.Width * scale;
            var   height = svg.ViewBox.Height * scale;

            var matrix = SKMatrix.Identity;

            if (rotate > 0)
            {
                matrix = matrix.PreConcat(SKMatrix.CreateRotationDegrees(rotate, (left + widthR / 2), (top + heightR / 2)));
            }

            matrix = matrix.PreConcat(SKMatrix.CreateTranslation(left + (widthR - width) / 2F, top + (heightR - height) / 2F));
            matrix = matrix.PreConcat(SKMatrix.CreateScale(scale, scale));

            return(matrix);
        }
Beispiel #4
0
        public static SKMatrix GetMatrix(SvgImage svg, SKRect bound, float indent, float rotate = 0)
        {
            bound.Inflate(-indent, -indent);

            return(GetMatrix(svg, bound.Left, bound.Top, bound.Width, bound.Height, rotate));
        }