我正在为Android和iOS开发便携式应用程序.我当前的功能是截取屏幕截图并在代码中使用该图像.因此我在便携式库中有一个接口.
public interface IFileSystemService
{
string GetAppDataFolder();
}
Run Code Online (Sandbox Code Playgroud)
我正在使用以下代码在可移植库中获取屏幕截图:
static public bool TakeScreenshot()
{
try
{
byte[] ScreenshotBytes = DependencyService.Get<Interface.IScreenshotManager>().TakeScreenshot();
return true;
}
catch (Exception ex)
{
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
这可以调用Android或iOS版本.
安卓:
class ScreenshotManagerAndroid : IScreenshotManager
{
public static Activity Activity { get; set; }
public byte[] TakeScreenshot()
{
if (Activity == null)
{
throw new Exception("You have to set ScreenshotManager.Activity in your Android project");
}
var view = Activity.Window.DecorView;
view.DrawingCacheEnabled = true;
Bitmap bitmap = view.GetDrawingCache(true);
byte[] bitmapData; …Run Code Online (Sandbox Code Playgroud)