在Google Maps SDK for iOS上执行GMSMapView的屏幕捕获问题 [英] Issue taking screen capture of GMSMapView on Google Maps SDK for iOS

查看:248
本文介绍了在Google Maps SDK for iOS上执行GMSMapView的屏幕捕获问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图截取GMSMapView(Google Maps SDK iOS)的任何部分的屏幕捕获时,我困扰的一个项目。 UIGraphicsGetImageFromCurrentImageContext()UIImage输出不可见。我最终发现GMSMapView是用OpenGL渲染的。知道了这一点,我试图使用glReadPixels()方法。麻烦的事情是,我能够检索在iPhone模拟器上的地图屏幕捕获很好,但是当我在真实的设备上使用相同的方法,它仍然是不可见的(iOS 6)。

An item that I am struggling with is when I attempt to take a screen capture of any portion of the GMSMapView (Google Maps SDK iOS). The UIGraphicsGetImageFromCurrentImageContext() UIImage output is invisible. I eventually discovered that the GMSMapView is rendered with OpenGL. Knowing this, I attempted to use the glReadPixels() method. The troubling thing is that I am able to retrieve a map screen capture on the iPhone simulator just fine, but when I use the same method on a real device it is still invisible (iOS 6).

我想知道是否有人遇到同样的问题?我已经做了我的调查的份额。我找不到任何与我的情况相关的。大多数通用解决方案,我发现我应该更新几个CAEAGLLayer属性。我以为GMSMapView中会限制我从寻找合适的层,但我能找到和更新CAEAGLLayer,如下所示:

I'm wondering if anyone has run into the same issue? I've done my share of investigating. I could not find anything relevant to my situation. Most of the generic solutions I did find said that I should update a few of the CAEAGLLayer attributes. I assumed the GMSMapView would limit me from finding the appropriate layer, but I was able to find and update the CAEAGLLayer, as seen below:

[(CAEAGLLayer *)[[[mapView_ subviews] objectAtIndex:0] layer] setOpaque: NO];

[(CAEAGLLayer *)[[[mapView_ subviews] objectAtIndex:0] layer] setDrawableProperties:[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES],kEAGLDrawablePropertyRetainedBacking,kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,nil]];



论坛建议由一层不透明的属性NO和保留备份属性设置为YES,将缓解iOS 6问题。它确实修复在模拟器上,但不是设备。

Forums recommended that by setting the layer's OPAQUE attribute to NO and the retained backing property to YES it would alleviate the iOS 6 issue. It did fix it on the simulator, but not the device.

我偶然发现的最后一个修复是将主OpenGL视图的preserveBackBuffer更新为YES。这是我的技术专业知识结束的地方。我还没有找到在哪里或如何更新GMSMapView的preserveBackBuffer值。我假设这是修复,将补救所有我的屏幕捕获问题。似乎只是运行iOS 6+的设备的问题。

The last fix I stumbled across said to update the main OpenGL view's preserveBackBuffer to YES. This is where my technical expertise ended. I have not been able to find where or how to update the GMSMapView's preserveBackBuffer value. I'm assuming this is the fix that will remedy all of my screen capture issues. Seems to be solely an issue with devices running iOS 6+.

有没有人有此问题的测试解决方法吗?

Does anyone have a tested workaround for this issue?

推荐答案

在谷歌地图iOS版V1.1,有GMSScreenshot类,可以实现这一点。

In Google Maps for iOS v1.1, there is GMSScreenshot class which can achieve this.

    UIImage* image = [GMSScreenshot screenshotOfMainScreen];

这在v1.2中已被移除,因为地图图层现在可以使用标准图形上下文方法。假设GMSMapView中是自我的子视图:

This has been removed in v1.2, though, as the map layer can now be captured using the standard graphics context methods. Assuming that GMSMapView is a subview of 'self':

- (UIImage *)captureScreen {
    UIGraphicsBeginImageContextWithOptions(self.frame.size, YES, 0.0f);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

这篇关于在Google Maps SDK for iOS上执行GMSMapView的屏幕捕获问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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