Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Chart (SciChart) not showing up on generated screenshot

I'm using the following code to create a Uri in order to share a screenshot of the current app view via email, etc:


    private Uri GetScreenshotUri()
    {
        var rawScreenshot = Capture();
        var uri = SaveImage(rawScreenshot);

        return uri;
    }

    private Uri SaveImage(Bitmap imageBytes)
    {
        Uri uri;
        try
        {
            var storagePath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
            var filePath = $"/{storagePath}/{DateTime.Now:yyyy-MM-dd_hh-mm-ss-tt}.png";
            using (var stream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
            {
                imageBytes.Compress(Bitmap.CompressFormat.Png, 100, stream);
            }

            var dir = new Java.IO.File(filePath);
            uri = Uri.FromFile(dir);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }

        return uri;
    }

    public Bitmap Capture()
    {
        var currentActivity = ((Activity)Xamarin.Forms.Forms.Context);
        var rootView = currentActivity.Window.DecorView.RootView;
        var screenshot = Bitmap.CreateBitmap(
            rootView.Width,
            rootView.Height,
            Bitmap.Config.Argb8888);
        var canvas = new Canvas(screenshot);
            rootView.Draw(canvas);

        return screenshot;
    }

This code works except that a third-party chart (SciCharts) that is in the middle of the screen does not show up on the screenshot (it just comes through as white space rather than showing the chart).
Any thoughts on why this may be happening/how I can get the chart to show up on the screenshot?

Tagged:
Sign In or Register to comment.