Google Map屏幕截图黑色 [英] Google Map Screenshot black

查看:157
本文介绍了Google Map屏幕截图黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的xamarin PCL项目中拍摄Google地图屏幕截图.地图显示完美.但是,当我尝试拍摄屏幕快照时,它会显示Google地图部分的黑屏.

I want to take google map screenshot in my xamarin PCL Project. The map is displaying perfectly. But when i try to take screenshot it is displaying black screen of the google map part.

但是当我尝试通过代码进行截屏时,屏幕截图如下所示.

But when i try to take by code screenshot is displaying like below.

public interface IScreenshotService
{
   Task<byte[]> Capture();
}


public class ScreenshotService : IScreenshotService
{
    public static Activity Activity { get; set; }

    //public void SetActivity(Activity activity) => _currentActivity = activity 

    public async System.Threading.Tasks.Task<byte[]> Capture()
    {
        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;

        using (var stream = new MemoryStream())
        {
            bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream);
            bitmapData = stream.ToArray();
        }

        return bitmapData;
    }
}

用于调用函数的代码

byte[] screenshotData = await DependencyService.Get<IScreenshotService>().Capture();

您能帮我解决问题吗?

推荐答案

我认为可能是地图图像不得传输到您的服务器,或在应用程序外部使用 您可以使用GoogleMap.snapshot方法拍摄地图快照

I think it might be Images of the map must not be transmitted to your servers, or otherwise used outside of the application and you could use GoogleMap.snapshot method to take snapshots of the map

只需实现以下接口: onSnapshotReady

public abstract void onSnapshotReady (Bitmap snapshot)

并致电:您还可以参考示例(在jave中):

you alse could refer to the example (in jave) :screenshot answer

这篇关于Google Map屏幕截图黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆