private static SkiaSharp.Extended.Svg.SKSvg LoadSVG(string key)
            {
                Assembly assembly = null;

                foreach (KeyValuePair <Assembly, List <string> > entry in ManifestResourceNames)
                {
                    if (entry.Value.Contains(key))
                    {
                        assembly = entry.Key;
                        break;
                    }
                }

                if (assembly == null)
                {
                    throw new Exception($"Failed to locate assembly for resource {key}");
                }

                // If not found in cache, load
                if (!SvgCache.TryGetValue(key, out SkiaSharp.Extended.Svg.SKSvg svg))
                {
                    using (Stream stream = assembly.GetManifestResourceStream(key))
                    {
                        svg = new SkiaSharp.Extended.Svg.SKSvg();
                        svg.Load(stream);
                        SvgCache.Add(key, svg);
                    }
                }
                return(svg);
            }
Exemple #2
0
        private void OnSvgResourceKeyChanged(string oldValue, string newValue)
        {
            //"XApp.Views.Icons.ZWave.svg"
            picture = null;

            if (!string.IsNullOrEmpty(newValue))
            {
                string resxId = newValue.IndexOf(".") > 0
                    ? newValue
                    : $"{typeof(SvgIcon).Namespace}.Svg.{newValue}.svg";

                if (!svgs.TryGetValue(resxId, out picture))
                {
                    using (Stream stream = GetType().Assembly.GetManifestResourceStream(resxId))
                    {
                        if (stream != null)
                        {
                            Svg.SKSvg svg = new Svg.SKSvg();
                            svg.Load(stream);
                            picture = svgs[resxId] = svg.Picture;
                        }
                    }
                }
            }
            InvalidateSurface();
        }
Exemple #3
0
    private void SaveVector(Shape shape)
    {
        var svg = new SkiaSharp.Extended.Svg.SKSvg();

        svg.Load(shape.OutputPath);

        var svgRect = svg.Picture.CullRect;

        var(w, h) = CalculateResized((int)svgRect.Width, (int)svgRect.Height);
        float svgMax = Math.Max(w, h);

        float scale   = w / svgRect.Width;
        var   matrixS = SKMatrix.MakeScale(scale, scale);
        var   matrixT = SKMatrix.MakeTranslation((MAX_SIZE - w) / 2, (MAX_SIZE - h) / 2);
        var   matrix  = SKMatrix.MakeIdentity();

        SKMatrix.Concat(ref matrix, matrixT, matrixS);

        var target = new SKBitmap(MAX_SIZE, MAX_SIZE,
                                  SKImageInfo.PlatformColorType, SKAlphaType.Premul);

        using (target)
            using (var canvas = new SKCanvas(target))
            {
                canvas.Clear();
                canvas.DrawPicture(svg.Picture, ref matrix, _skPaint);
                SaveToFile(shape.Id, "svg", target);
            }
    }
        public SKSvg Load(string svgImage)
        {
            try
            {
                var    svg   = new SkiaSharp.Extended.Svg.SKSvg();
                Stream asset = null;

                try
                {
                    asset = Application.Context.Assets.Open(svgImage);
                }
                catch (Exception)
                {
                    throw new Exception($"SVG-file, {svgImage} cannot be foundin the Asset folder.");
                }

                svg.Load(asset);

                return(svg);
            }
            catch (Exception)
            {
                throw new Exception($"SVG-file, {svgImage} is not supported by SkiaSharp.Svg.");
            }
        }
Exemple #5
0
        public SKSvg Load(string svgImage)
        {
            var svg = new SkiaSharp.Extended.Svg.SKSvg();

            svg.Load(svgImage);

            return(svg);
        }
Exemple #6
0
        };                                                                                                    // Only for high/med/low quality resizing of tiles

        public static BitmapInfo LoadBitmap(Stream bitmapStream, bool isSvg = false)
        {
            bitmapStream.Position = 0;
            if (isSvg)
            {
                var svg = new SkiaSharp.Extended.Svg.SKSvg();
                svg.Load(bitmapStream);

                return(new BitmapInfo {
                    Svg = svg
                });
            }

            var image = SKImage.FromEncodedData(SKData.CreateCopy(bitmapStream.ToBytes()));

            return(new BitmapInfo {
                Bitmap = image
            });
        }
Exemple #7
0
        //Create the event handler
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;

            DriveViewModel vm = this.BindingContext as DriveViewModel;

            if (vm == null)
            {
                return;
            }


            using (var webClient = new WebClient()) {
                var canvas = surface.Canvas;

                var stream = webClient.DownloadData($"http://{Models.AppConfig.Instance.IpAddress}:8080/image/front/img.jpg?timestamp={DateTime.Now.Ticks}");
                var img    = SKBitmap.Decode(stream);


                SKRect bounds = canvas.LocalClipBounds;
                float  xRatio = (float)info.Width / (float)img.Width;
                float  yRatio = (float)info.Height / (float)img.Height;
                canvas.Scale(xRatio, yRatio);

                canvas.DrawBitmap(img, 0, 0);                //, canvas.LocalClipBounds);

                if (vm.ShowGrass)
                {
                    try {
                        var streamGrass = webClient.DownloadData($"http://{Models.AppConfig.Instance.IpAddress}:8080/image/front/grass.svg?timestamp={DateTime.Now.Ticks}&layerItems=detection&layerItems=surface&layerItems=robotMotionState&layerItems=inferenceType");
                        //SKSvg svgGrass = new SkiaSharp.SKSvg();
                        SkiaSharp.Extended.Svg.SKSvg svg = new SkiaSharp.Extended.Svg.SKSvg();
                        svg.Load(new MemoryStream(streamGrass));

                        canvas.DrawPicture(svg.Picture);
                    } catch (Exception err) {
                    }
                }
                if (vm.ShowScene)
                {
                    try {
                        var streamScene = webClient.DownloadData($"http://{Models.AppConfig.Instance.IpAddress}:8080/image/front/scene.svg?timestamp={DateTime.Now.Ticks}&layerItems=GeneralObjectDetectionTransformer&layerItems=ToadiObjectDetectionTransformer&layerItems=ChargingStationPoseTransformer");

                        SkiaSharp.Extended.Svg.SKSvg svgScene = new SkiaSharp.Extended.Svg.SKSvg();
                        svgScene.Load(new MemoryStream(streamScene));


                        canvas.DrawPicture(svgScene.Picture);
                    } catch (Exception err) {
                    }
                }



                img.Dispose();
                canvas.Dispose();

                //using (var canvas = surface.Canvas) {
                //	// use KBitmap.Decode to decode the byte[] in jpeg format
                //	using (var bitmap = SKBitmap.Decode(stream)) {

                //		using (var paint = new SKPaint()) {
                //			// clear the canvas / fill with black
                //			//canvas.DrawColor(SKColors.Black);
                //			canvas.DrawBitmap(bitmap, canvas.LocalClipBounds);
                //			//canvas.DrawBitmap(bitmap, 0, 0, paint); // SKRect.Create(640, 480)
                //			//canvas.DrawBitmap(bitmap, SKRect.Create(640, 480), SKRect.Create((float)canvasView.Width, (float)canvasView.Height));
                //		}

                //	}
                //}
            }
        }
Exemple #8
0
        public static void CreateOgImage(
            [QueueTrigger("ClassifyResultCreate")] string input,
            [Table("ClassifyResult", "ja-en", "{queueTrigger}")] ResponseTableEntity tableEntity,
            [Blob("classifyresultogimage/{queueTrigger}.png", FileAccess.Write)] Stream imageStream,
            ILogger log)
        {
            log.LogInformation($"Handle {input}");
            var response     = JsonConvert.DeserializeObject <Response>(tableEntity.ResponseData);
            var barFactor    = 600;
            var adultBar     = response.Categories.First(x => x.Name == "Adult").Score *barFactor;
            var racyBar      = response.Categories.First(x => x.Name == "Racy").Score *barFactor;
            var offensiveBar = response.Categories.First(x => x.Name == "Offensive").Score *barFactor;
            var svgString    = $@"<?xml version=""1.0""?>
<svg width=""960""
     height=""480""
     xmlns=""http://www.w3.org/2000/svg""
     xmlns:svg=""http://www.w3.org/2000/svg"">
  <g class=""layer"">
    <text fill=""#000000""
          font-family=""Meiryo""
          font-size=""48""
          id=""svg_1""
          stroke=""#000000""
          stroke-width=""0""
          text-anchor=""start""
          x=""32""
          y=""48"">JapaniseTextClassifier</text>
    <switch>
      <foreignObject x=""64""
                     y=""64""
                     width=""832""
                     height=""240"">
        <p xmlns=""http://www.w3.org/1999/xhtml"" style=""font-size: 24px; font-family: Meiryo;"">
          {response.Request.Text}
        </p>
      </foreignObject>

      <text fill=""#000000""
            font-family=""Meiryo""
            font-size=""24""
            id=""svg_2""
            stroke=""#000000""
            stroke-width=""0""
            text-anchor=""start""
            x=""64""
            y=""96"">{response.Request.Text}</text>
    </switch>
    <text fill=""#000000""
          font-family=""Meiryo""
          font-size=""24""
          id=""svg_3""
          stroke=""#000000""
          stroke-width=""0""
          text-anchor=""start""
          x=""64""
          y=""370"">Adult</text>
    <text fill=""#000000""
          font-family=""Meiryo""
          font-size=""24""
          id=""svg_4""
          stroke=""#000000""
          stroke-width=""0""
          text-anchor=""start""
          x=""64""
          y=""410"">Racy</text>
    <text fill=""#000000""
          font-family=""Meiryo""
          font-size=""24""
          id=""svg_5""
          stroke=""#000000""
          stroke-width=""0""
          text-anchor=""start""
          x=""64""
          y=""450"">Offensive</text>
    <rect fill=""#000000""
          height=""32""
          id=""svg_6""
          stroke=""#000000""
          stroke-width=""5""
          width=""{adultBar}""
          x=""240""
          y=""340""/>
    <rect fill=""#000000""
          height=""32""
          id=""svg_7""
          stroke=""#000000""
          stroke-width=""5""
          width=""{racyBar}""
          x=""240""
          y=""380""/>
    <rect fill=""#000000""
          height=""32""
          id=""svg_8""
          stroke=""#000000""
          stroke-width=""5""
          width=""{offensiveBar}""
          x=""240""
          y=""420""/>
  </g>
</svg>";
            var svg          = new SkiaSharp.Extended.Svg.SKSvg();
            var pict         = svg.Load(new MemoryStream(Encoding.UTF8.GetBytes(svgString)));
            var dimen        = new SKSizeI(
                (int)Math.Ceiling(pict.CullRect.Width),
                (int)Math.Ceiling(pict.CullRect.Height)
                );
            var matrix  = SKMatrix.MakeScale(1, 1);
            var img     = SKImage.FromPicture(pict, dimen, matrix);
            var quality = 90;
            var skdata  = img.Encode(SkiaSharp.SKEncodedImageFormat.Png, quality);

            skdata.SaveTo(imageStream);
            log.LogInformation(svgString);
        }