我已经将mapview隐藏在我的应用程序中。地图图像需要从mapview中获取并作为电子邮件发送。我如何从隐藏的mapview中获取地图图像。从MKMapView获取地图图像
感谢,使用CGBitmapContextCreate
[mapView.layer renderInContext:myContext]
CGImage
渲染MKMapView
使用CGBitmapContextCreateImage
CGImage
到UIImage
如果需要我已经将mapview隐藏在我的应用程序中。地图图像需要从mapview中获取并作为电子邮件发送。我如何从隐藏的mapview中获取地图图像。从MKMapView获取地图图像
感谢,使用CGBitmapContextCreate
[mapView.layer renderInContext:myContext]
CGImage
渲染MKMapView
使用CGBitmapContextCreateImage
CGImage
到UIImage
如果需要对于SDK:
UIGraphicsBeginImageContext(self.mapView.bounds.size);
[self.mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();
对于工具链(使用私人API)
CGRect rect = [self.mapView bounds];
// Change the snapshot rect if needed.
CGImageRef image = [self.mapView createSnapshotWithRect:rect];
我似乎无法得到这个适用于iPhone 4s ....所有其他设备都很好,包括模拟器......想法? – mlecho 2011-12-22 01:29:02
对于任何人碰到这个未来现在有一个叫做MKMapSnapshotter类可能会有所帮助 – shim 2017-07-06 21:56:09