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()); }
/// <summary> /// Initializes a new instance of the <see cref="RectangleMode"/> class. /// </summary> public SvgSquaresMode() { // Create a list of gem images. SceneNodeLinkedList<float> nodes = new SceneNodeLinkedList<float>(); RootSceneNode = nodes; // Load the image into memory. svgLoader = new SvgLoader(new FileInfo("Images/1cm.svg")); float screenScale = Platform.Instance.Window.Resolution.Height / 16f; svgLoader.Scale = screenScale * SvgImageLoader.Meter100px; TextureLoader textureLoader = new TextureLoader(svgLoader); // Create squares across the board. rows = (int) (440 / screenScale); columns = (int) (600 / (2 * screenScale)); for (int i = 0; i < columns; i++) { for (int j = 0; j < rows; j++) { ImageNode<float> image = new ImageNode<float>(textureLoader); image.Point = new Point2<float>((j % 2) * screenScale + i * 2 * screenScale, j * screenScale); if (i % 4 == 0) image.Tint = new Color<float>(1, 1, 0, 0); if (j % 4 == 0) image.Tint = new Color<float>(1, 0, 1, 0); nodes.Add(image); } } }
protected override async Task OnInitializedAsync() { if (!string.IsNullOrWhiteSpace(Source)) { Markup = AddClass(await SvgLoader.LoadSvg(Source)); } }
protected override async Task OnInitializedAsync() { if (!string.IsNullOrWhiteSpace(Src)) { Markup = await SvgLoader.LoadSvg(Src); } }
public static ImageSource FromFilePathToImageSource(string svgFilePath) { var svgStream = File.Open(svgFilePath, FileMode.Open, FileAccess.Read); var svgImage = SvgLoader.LoadFromStream(svgStream); var size = new Size(svgImage.Width * ScreenHelper.ScaleX, svgImage.Height * ScreenHelper.ScaleX); return(WpfSvgRenderer.CreateImageSource(svgImage, size, null, null, true)); }
public GuiSvgSamples(ICoreClientAPI capi) : base(capi) { try { // attempt creation of rasterizer svgLoader = new SvgLoader(capi); SetupPages(); SetupGui(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
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); }
/// <summary> /// Converts a value. /// </summary> /// <param name="value">The value produced by the binding source.</param> /// <param name="targetType">The type of the binding target property.</param> /// <param name="parameter">The converter parameter to use.</param> /// <param name="culture">The culture to use in the converter.</param> /// <returns> /// A converted value. If the method returns null, the valid null value is used. /// </returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var uri = uriConverter.ConvertFrom(value) as Uri; if (uri == null) { return(DependencyProperty.UnsetValue); } var absoluteUri = uri.IsAbsoluteUri ? uri : new Uri(baseUri, uri); using (var stream = GetStream(absoluteUri)) { var image = SvgLoader.LoadFromStream(stream); return(WpfSvgRenderer.CreateImageSource(image, 1d, null, null, true)); } }
/// <summary> /// Initializes a new instance of the <see cref="RectangleMode"/> class. /// </summary> public SvgSquaresMode() { // Create a list of gem images. SceneNodeLinkedList <float> nodes = new SceneNodeLinkedList <float>(); RootSceneNode = nodes; // Load the image into memory. svgLoader = new SvgLoader(new FileInfo("Images/1cm.svg")); float screenScale = Platform.Instance.Window.Resolution.Height / 16f; svgLoader.Scale = screenScale * SvgImageLoader.Meter100px; TextureLoader textureLoader = new TextureLoader(svgLoader); // Create squares across the board. rows = (int)(440 / screenScale); columns = (int)(600 / (2 * screenScale)); for (int i = 0; i < columns; i++) { for (int j = 0; j < rows; j++) { ImageNode <float> image = new ImageNode <float>(textureLoader); image.Point = new Point2 <float>((j % 2) * screenScale + i * 2 * screenScale, j * screenScale); if (i % 4 == 0) { image.Tint = new Color <float>(1, 1, 0, 0); } if (j % 4 == 0) { image.Tint = new Color <float>(1, 0, 1, 0); } nodes.Add(image); } } }