gFinger 손끝으로 만드는 세상

 

 

 

Table Of Contens

1. Class Example

2. Reference

1. Example

 
  class ProcessingSVG
    {
        public List SVGlist = new List();

        // SVG를 처리하는 Class
        public class SvgClass
        {   
            private SkiaSharp.Extended.Svg.SKSvg svg;  

           
            // Get file .svg to folder Images 
            // Form Embeded Resoure 
            Stream GetImageStream(string svgName, Type PageType)
            {

                TypeInfo PageInfo = PageType.GetTypeInfo();
                Assembly assembly = PageInfo.Assembly;

                var abc = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.Images.{svgName}");
                return abc;
            }
 

            //  return picture of the SVG
            public SKPicture GetPicture()
            {
                return svg.Picture;
            }

            public void LoadSvg(string svgName, Type PageType)
            {
                // create a new SVG object
                svg = new SkiaSharp.Extended.Svg.SKSvg(); 
                // load the SVG document from a stream 
                using (var stream = GetImageStream(svgName, PageType))
                    svg.Load(stream);
            }
        } 
    }
    
    
    
        // Save  SVG File 
        ProcessingSVG XX_SVG = new ProcessingSVG();
        const int NumberOfSVG = 10;
        void LoadSVGimage()
        {
            // Data Exist
            if (XX_SVG.SVGlist != null) XX_SVG.SVGlist.Clear();

            for(int i=0; i< NumberOfSVG; i++)
            {
                var oneSVG = new ProcessingSVG.SvgClass();
                oneSVG.LoadSvg("test"+i.ToString()+".svg", typeof(MainPage));
                XX_SVG.SVGlist.Add(oneSVG); 
            } 
        }
        

       // Draw SVG Picture
          canvasXX.Save();
          canvasXX.Scale(0.1f); 
          canvasXX.DrawPicture(XX_SVG.SVGlist[7].GetPicture(), 0,0);
          canvasXX.Restore();
          
          

 

2. Reference


https://stackoverflow.com/questions/58259473/how-to-load-file-svg-with-skiasharp-on-xamarin-forms