컴퓨터 이야기/xamarin
[xamarin] How to load file .svg with SkiaSharp on Xamarin forms?
golfin
2020. 5. 13. 09:56
Table Of Contens 1. Class Example |
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