private void SvgAnimPlayer_Unloaded(object sender, RoutedEventArgs e) { lock (_lockobj) { _win2DSvg?.Dispose(); _win2DSvg = null; _handBitmap?.Dispose(); _handBitmap = null; }; }
private async Task <CanvasImageSource> SvgToImageSource(SvgElement svg) { if (svg == null) { return(null); } var device = CanvasDevice.GetSharedDevice(); using (var win2DSvg = await Win2DSvgElement.Parse(device, svg)) { win2DSvg.Progress = 1; var offScreen = new CanvasImageSource(device, (float)_cacheImageResolution.Width, (float)_cacheImageResolution.Height, 96); using (var drawingSession = offScreen.CreateDrawingSession(Colors.Transparent)) { drawingSession.Transform = Matrix3x2.CreateTranslation(new Vector2(-(float)svg.ViewBox.X, -(float)svg.ViewBox.Y)) * Matrix3x2.CreateScale((float)(200 / Math.Max(svg.ViewBox.Width, svg.ViewBox.Height))); win2DSvg.Draw(drawingSession, 0); } return(offScreen); } }