public static async Task<Bitmap> GetBitmapAsync (SvgImage svgImage, int width, int height)
		{
			Bitmap result = null;

			Stream svgStream = await SvgService.GetSvgStreamAsync (svgImage).ConfigureAwait (false);

      await Task.Run(() =>
      {
          var svgReader = new SvgReader(new StreamReader(svgStream));

        var graphics = svgReader.Graphic;

        var scale = 1.0;

        if (height >= width)
        {
          scale = height / graphics.Size.Height;
        }
        else
        {
          scale = width / graphics.Size.Width;
        }

        var canvas = new AndroidPlatform().CreateImageCanvas(graphics.Size, scale);
        graphics.Draw(canvas);
        var image = (BitmapImage)canvas.GetImage();
        result = image.Bitmap;
      });

			return result;
		}
Esempio n. 2
0
        public Task<ProviderPackage> GetAsync(EventCaller caller, string inputContent)
        {
            return Task.Run(() =>
            {
                var htmlTree = new HtmlDocument();
                htmlTree.LoadHtml(inputContent);
                var node = htmlTree.DocumentNode.QuerySelector(".b_anno");
                var stockNode = htmlTree.DocumentNode.QuerySelector(".b_hPanel");
                var trendMap = htmlTree.DocumentNode.QuerySelector("svg");

                if (node != null && stockNode != null)
                {
                    if (trendMap != null)
                    {
                        var w = trendMap.Attributes["width"];
                        var h = trendMap.Attributes["height"];
                        var trendMapContent = string.Format("<svg width=\"{0}\" height=\"{1}\">{2}</svg>", w.Value, h.Value, trendMap.InnerHtml);

                        var trendMapXml = new XmlDocument();
                        trendMapXml.LoadXml(trendMapContent);

                        var reader = new SvgReader(new StringReader(trendMapContent));
                        var graphic = reader.Graphic;
                        var c =
                            Platforms.Current.CreateImageCanvas(
                                new NGraphics.Size(double.Parse(w.Value), double.Parse(h.Value)), scale: 1);
                        graphic.Draw(c);
                        var trendMapImageStream = new MemoryStream();
                        c.GetImage().SaveAsPng(trendMapImageStream);

                        // Send Package
                        return new ProviderPackage(string.Format("{0} : {1}", node.InnerText, stockNode.InnerText)
                            , trendMapImageStream, caller, Priority);
                    }
                    return new ProviderPackage(string.Format("{0} : {1}", node.InnerText, stockNode.InnerText),
                            caller, Priority);
                }

                return ProviderPackage.ReturnNotAvailablePackage();
            });
        }
        public static Graphic ParseSvg(string svg, double pixelsPerInch = SvgReader.DefaultPixelsPerInch, Brush defaultBrush = null, Font defaultFont = null)
        {
            var svgr = new SvgReader(svg, pixelsPerInch: pixelsPerInch, defaultBrush: defaultBrush, defaultFont: defaultFont);

            return(svgr.Graphic);
        }
        public static Graphic LoadSvg(System.IO.TextReader reader, double pixelsPerInch = SvgReader.DefaultPixelsPerInch, Brush defaultBrush = null, Font defaultFont = null)
        {
            var svgr = new SvgReader(reader, pixelsPerInch: pixelsPerInch, defaultBrush: defaultBrush, defaultFont: defaultFont);

            return(svgr.Graphic);
        }
Esempio n. 5
0
		public void LoadSvgFromResource ()
		{
			if (SvgAssembly == null || SvgPath == null) {
				// Can be called by OnPropertyChanged as values are initially defined.
				// Don't load anything until we are sure we have enough to do so.
				return;
			}

			var svgStream = SvgAssembly.GetManifestResourceStream (SvgPath);

			if (svgStream == null) {
				throw new Exception (string.Format ("Error retrieving {0} make sure Build Action is Embedded Resource",
					SvgPath));
			}

			var r = new SvgReader (new StreamReader (svgStream));

			LoadedGraphic = r.Graphic;
		}
Esempio n. 6
0
        public static Graphic LoadSvg(System.IO.TextReader reader)
        {
            var svgr = new SvgReader(reader);

            return(svgr.Graphic);
        }
Esempio n. 7
0
		public static Graphic LoadSvg (System.IO.TextReader reader)
		{
			var svgr = new SvgReader (reader);
			return svgr.Graphic;
		}
Esempio n. 8
0
        public static Graphic LoadSvg(System.IO.TextReader reader, Brush defaultBrush = null)
        {
            var svgr = new SvgReader(reader, defaultBrush: defaultBrush);

            return(svgr.Graphic);
        }