private async Task ShareEmotion(EmotionData Data)
        {
            Chart chart = new BarChart();

            chart            = DayChart as BarChart;
            chart.IsAnimated = false;
            chart.Margin     = 20;
            chart.LabelColor = SKColors.Purple;


            var bmp    = new SKBitmap(500, 500);
            var canvas = new SKCanvas(bmp);
            var image  = SKImage.FromPixels(bmp.PeekPixels());

            chart.DrawContent(canvas, 500, 500);
            canvas.Save();


            using (MemoryStream ms = new MemoryStream())
            {
                image.Encode(SKEncodedImageFormat.Png, 4).AsStream().CopyTo(ms);

                var str = Convert.ToBase64String(ms.ToArray());
                bytes = Convert.FromBase64String(str);
            }
            try
            {
                PermissionStatus status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);

                if (status != PermissionStatus.Granted)
                {
                    var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Storage });

                    status = results[Permission.Storage];
                }

                if (status != PermissionStatus.Granted)
                {
                    return;
                }
                else
                {
                    DependencyService.Get <IShare>()
                    .ShareContent("", "AboutSelf", ImageSource.FromStream(() => new MemoryStream(bytes)));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Exemple #2
0
        public void MicrochartChart()
        {
            var entries = new[]
            {
                new ChartEntry(212)
                {
                    Label      = "UWP",
                    ValueLabel = "112",
                    Color      = SKColor.Parse("#2c3e50")
                },
                new ChartEntry(248)
                {
                    Label      = "Android",
                    ValueLabel = "648",
                    Color      = SKColor.Parse("#77d065")
                },
                new ChartEntry(128)
                {
                    Label      = "iOS",
                    ValueLabel = "428",
                    Color      = SKColor.Parse("#b455b6")
                },
                new ChartEntry(514)
                {
                    Label      = "Forms",
                    ValueLabel = "214",
                    Color      = SKColor.Parse("#3498db")
                }
            };

            RenderingTest
            .Create()
            .PageSize(400, 600)
            .ProduceImages()
            .ShowResults()
            .Render(container =>
            {
                container
                .Background(Colors.White)
                .Padding(25)
                .Column(column =>
                {
                    column
                    .Item()
                    .PaddingBottom(10)
                    .Text("Chart example")
                    .FontSize(20)
                    .SemiBold()
                    .FontColor(Colors.Blue.Medium);

                    column
                    .Item()
                    .Border(1)
                    .ExtendHorizontal()
                    .Height(300)
                    .Canvas((canvas, size) =>
                    {
                        var chart = new BarChart
                        {
                            Entries = entries,

                            LabelOrientation      = Orientation.Horizontal,
                            ValueLabelOrientation = Orientation.Horizontal,

                            IsAnimated = false,
                        };

                        chart.DrawContent(canvas, (int)size.Width, (int)size.Height);
                    });
                });
            });
        }
Exemple #3
0
        private static void WriteImage(Options options, Summary summary, string file)
        {
            var chartEntries = new List <ChartEntry>();

            double maxValue = 0;

            foreach (var benchmarkReport in summary.Reports)
            {
                var meanMs = ConvertNanosecondsToMilliseconds(benchmarkReport.ResultStatistics.Mean);

                if (meanMs > maxValue)
                {
                    maxValue = meanMs;
                }
            }


            foreach (var benchmarkReport in summary.Reports)
            {
                var meanMs = ConvertNanosecondsToMilliseconds(benchmarkReport.ResultStatistics.Mean);

                var methodDisplayInfo = benchmarkReport.BenchmarkCase.Descriptor.WorkloadMethodDisplayInfo;

                SKColor color;

                if (methodDisplayInfo.Contains("Deserialize", StringComparison.OrdinalIgnoreCase))
                {
                    color = SKColor.Parse("#ff944d");
                }
                else
                {
                    color = SKColor.Parse("#6666ff");
                }

                var value = (float)(meanMs / maxValue);
                chartEntries.Add(new ChartEntry(value)
                {
                    ValueLabelColor = new SKColor(10, 10, 10),
                    TextColor       = new SKColor(1, 10, 10),
                    Color           = color,
                    Label           = methodDisplayInfo,
                    ValueLabel      = meanMs.ToString("#.## ms")
                });
            }

            var chart = new BarChart
            {
                Entries               = chartEntries,
                LabelOrientation      = Orientation.Horizontal,
                ValueLabelOrientation = Orientation.Horizontal,
                LabelTextSize         = 14,
                Typeface              = SKTypeface.Default,
                MaxValue              = 1.15f,
                AnimationDuration     = TimeSpan.Zero,
            };

            chart.IsAnimated = true;  //seems stupid but there is some strange bug when building on git actions where it tries to animate so do not remove this
            chart.IsAnimated = false; //seems stupid but there is some strange bug when building on git actions where it tries to animate so do not remove this

            var width = 1400;

            var height = 700;

            var info = new SKImageInfo(width, height, SKColorType.Rgba8888);

            using (var surface = SKSurface.Create(info))
            {
                SKCanvas canvas = surface.Canvas;
                canvas.Clear(SKColors.Transparent);

                canvas.Translate(0, 100);

                chart.DrawContent(canvas, width, height - 100);
                canvas.Translate(0, -100);

                var paint = new SKPaint
                {
                    IsAntialias = true,
                    Color       = new SKColor(0x2c, 0x3e, 0x50),
                    StrokeCap   = SKStrokeCap.Round,
                    TextSize    = 20
                };

                canvas.DrawText($"{DateTime.Now.ToLongDateString()}  {options.Commit}", new SKPoint(50, 25), paint);

                canvas.Flush();

                canvas.Save();

                var snapshot = surface.Snapshot();

                using (var data = snapshot.Encode(SKEncodedImageFormat.Png, 80))
                {
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }

                    using (var stream = File.OpenWrite(file))
                    {
                        data.SaveTo(stream);
                    }
                }
            }
        }