Overview: I would like to take a screenshot, turn it into a byte array and then upload it to a server. I'm using Xamarin.Forms for Visual Studio Mac.
The target device is an Android Emulator Tablet.
Tried a lot but I'm not that good in C#.
The piece of code I want to implement:
var screenshot = await Screenshot.CaptureAsync();
var byte[] array;
using (MemoryStream ms = new MemoryStream())
{
screenshot.CopyTo(ms);
array = ms.ToArray();
}
The code I want to implement it in:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NativeMedia;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace UploadingFiles
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async void DoPDFThings(object sender, EventArgs e)
{
var screenshot = await Screenshot.CaptureAsync();
await MediaGallery.SaveAsync(MediaFileType.Image, await screenshot.OpenReadAsync(), "myScreenshot.png");
}
}
}
What I have tried:
I have tried to paste it under my code but then I got multiple red underlines, specifically under 'screenshot', 'var', 'byte' and 'CopyTo'.