开发者

Get map image from MKMapView

I have place a mapview as hidden in my application. The map image need to be obtained from the mapview and send as email. H开发者_StackOverflowow can i get the map image from the hidden mapview.

Thanks,


For SDK:

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

For toolchain (using Private API)

CGRect rect = [self.mapView bounds];
// Change the snapshot rect if needed. 
CGImageRef image = [self.mapView createSnapshotWithRect:rect];


  1. Setup pixel context using CGBitmapContextCreate
  2. Render MKMapView using [mapView.layer renderInContext:myContext]
  3. Get CGImage from context using CGBitmapContextCreateImage
  4. Wrap CGImage into UIImage if needed.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜