public static UIImage GetUIImage(string resource, double width, double height, Xamarin.Forms.Color color) { if (color == Xamarin.Forms.Color.Default) { return(GetUIImage(resource, width, height)); } var g = SvgLoader.GetResourceAndLoadSvg(resource); var transform = Transform.AspectFillRect(g.ViewBox, new Rect(0, 0, width, height)); var transGraphic = g.TransformGeometry(transform); var canvas = Platforms.Current.CreateImageCanvas( new NGraphics.Size(width, height), UIScreen.MainScreen.Scale); var nColor = new NGraphics.Color(color.R, color.G, color.B, color.A); foreach (var element in transGraphic.Children) { ApplyColor(element, nColor); element.Draw(canvas); } return(canvas.GetImage().GetUIImage()); }
public static UIImage GetUIImage(string resource, double width, double height) { var g = SvgLoader.GetResourceAndLoadSvg(resource); var transform = Transform.AspectFillRect(g.ViewBox, new Rect(0, 0, width, height)); var transGraphic = g.TransformGeometry(transform); var canvas = Platforms.Current.CreateImageCanvas( new NGraphics.Size(width, height), UIScreen.MainScreen.Scale); transGraphic.Draw(canvas); return(canvas.GetImage().GetUIImage()); }
public static Bitmap GetBitmap(string resource, double width, double height) { var g = SvgLoader.GetResourceAndLoadSvg(resource); double scale = (int)Android.App.Application.Context.Resources.DisplayMetrics.DensityDpi / 160d; var transform = Transform.AspectFillRect(g.ViewBox, new NGraphics.Rect(0, 0, width, height)); var transGraphic = g.TransformGeometry(transform); var canvas = Platforms.Current.CreateImageCanvas(new NGraphics.Size(width, height), scale); transGraphic.Draw(canvas); return((canvas.GetImage() as NGraphics.BitmapImage)?.Bitmap); }