小编Lex*_*exu的帖子

获取最新活动 - Xamarin Android

我正在为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)

c# android xamarin.android android-activity xamarin

16
推荐指数
4
解决办法
2万
查看次数

标签 统计

android ×1

android-activity ×1

c# ×1

xamarin ×1

xamarin.android ×1