[英]How can I take a partial screenshot of my Xamarin.Forms app and save it into my gallery?
I am using 2 packages for this:我为此使用了 2 个软件包:
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) 1- ImageFromXamarinUI :“从 UI 捕获图像的扩展方法”(我使用 x:Name="ScreenshotThis" 然后在 C# 中编写代码来截取具有 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 ) 2- Xamarin.MediaGallery:“用于从 iOS 和 Android 的本地图库中挑选和保存照片和视频的包”(我用来截取完整 UI 的屏幕截图并保存,效果很好)
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:问题:我尝试使用 ImageFromXamarinUI 获取特定的屏幕截图,并使用 Xamarin.MediaGallery 将图像保存在我的本机画廊(Android)中,但我收到此错误:
My xaml.cs code, which is where I am getting the error我的 xaml.cs 代码,这是我得到错误的地方
Here's a look at my Xaml code:这是我的 Xaml 代码:
The code where the button prompts the user to take screenshot of UI按钮提示用户截取 UI 的代码
You need to use a stream in the MediaGallery.SaveAsync
method.您需要在MediaGallery.SaveAsync
方法中使用流。 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 MediaGallery插件的使用方法可以查看官方文档: https ://github.com/dimonovdd/Xamarin.MediaGallery#saveasync
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.