Google Map屏幕截图黑色 [英] Google Map Screenshot black
问题描述
我想在我的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)
you alse could refer to the example (in jave) :screenshot answer
这篇关于Google Map屏幕截图黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!