2009-10-12 62 views
8

我已经将mapview隐藏在我的应用程序中。地图图像需要从mapview中获取并作为电子邮件发送。我如何从隐藏的mapview中获取地图图像。从MKMapView获取地图图像

感谢,使用CGBitmapContextCreate

  • 使用[mapView.layer renderInContext:myContext]
  • 获取从上下文CGImage渲染MKMapView使用CGBitmapContextCreateImage
  • CGImageUIImage如果需要

  • +0

    对于任何人碰到这个未来现在有一个叫做MKMapSnapshotter类可能会有所帮助 – shim 2017-07-06 21:56:09

    回答

    0
    1. 设置像素的上下文。
    12

    对于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]; 
    
    +0

    我似乎无法得到这个适用于iPhone 4s ....所有其他设备都很好,包括模拟器......想法? – mlecho 2011-12-22 01:29:02