从MKMapView获取地图图像

Tim*_*mmi 8 iphone

我在我的应用程序中隐藏了一个mapview.地图图像需要从mapview获取并作为电子邮件发送.如何从隐藏的mapview中获取地图图像.

谢谢,

Mik*_*hen 12

对于SDK:

UIGraphicsBeginImageContext(self.mapView.bounds.size);
[self.mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();
Run Code Online (Sandbox Code Playgroud)

对于工具链(使用私有API)

CGRect rect = [self.mapView bounds];
// Change the snapshot rect if needed. 
CGImageRef image = [self.mapView createSnapshotWithRect:rect];
Run Code Online (Sandbox Code Playgroud)


Nik*_*uhe 0

  1. 使用设置像素上下文CGBitmapContextCreate
  2. 渲染MKMapView使用[mapView.layer renderInContext:myContext]
  3. CGImage使用从上下文中获取CGBitmapContextCreateImage
  4. 如果需要的话,包裹CGImage进去UIImage