Home > Back-end >  How can I take a partial screenshot of my Xamarin.Forms app and save it into my gallery?
How can I take a partial screenshot of my Xamarin.Forms app and save it into my gallery?

Time:05-25

I am using 2 packages for this:

1- ImageFromXamarinUI : "Extension methods for capturing images from UI" ( I use x:Name="ScreenshotThis" and then write code in C# to take a screenshot of the specific thing that has the ID)

2- Xamarin.MediaGallery : "Package for picking and saving photos and videos from the native gallery of iOS and Android" ( I used in taking a screenshot of the FULL UI and saving it, works great )

Problem: I tried to use ImageFromXamarinUI to take the specific screenshot and Xamarin.MediaGallery to save the image in my native gallery (Android) but I get this error:

My xaml.cs code, which is where I am getting the error

Here's a look at my Xaml code:

The code where the button prompts the user to take screenshot of UI

CodePudding user response:

You need to use a stream in the MediaGallery.SaveAsync method. Such as:

await MediaGallery.SaveAsync(MediaFileType.Image,imageStream, "myScreenshot.png");

You can check the official document about how to use the MediaGallery plugin:https://github.com/dimonovdd/Xamarin.MediaGallery#saveasync

  • Related