I have a class with all the flags for each country. This is a normal C# class and you can see the source code on GitHub. Now, I have my .NET8
MAUI
application and I want to display an SVG image from this class.
I created a SKCanvasView
and I passed the SVG string to it. To simplify the example, I add the code of the flag in the OnPaintSurface
private SKSurface surface;
private SKCanvas canvas;
private SKSvg Svg { get; }
protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
info = e.Info;
surface = e.Surface;
Canvas = surface.Canvas;
Canvas.Clear();
byte[] bytes = Encoding.UTF8.GetBytes(SVGFlags.lgbt_1);
using var stream = new MemoryStream(bytes);
Svg.Load(stream);
canvas.DrawPicture(Svg.Picture);
}
The result is the following:
In this case, I wanted to show the LGBT flag but I get only the top left corner of it.
The SVG starts with
<svg xmlns='http://www.w3.org/2000/svg' width='75' height='75'
viewBox='0 0 75 75'>
<!-- full SVG -->
</svg>
Do I have to apply some sort of zoom to the SVG? If yes, how?