【问题标题】:MKMapView -> to UIImage -> to NSDataMKMapView -> 到 UIImage -> 到 NSData
【发布时间】:2011-08-21 09:45:13
【问题描述】:

对于 MKMapView:UIView

如何将 mkmapview 的内容转换为 uiimage?

虽然从 mkmapview 来看,最终目标(或 主要主要目标,如果你知道我的意思的话)是一个 NSData var,然后我可以使用 mimeType“image/png”将其附加到电子邮件中

有点像在任何给定时刻抓取 MKMapview 显示的任何内容的屏幕截图

把它放在 (UIImage)mapImage 上

NSData *imageData= UIImagePNGRepresentation(mapImage);

有什么建议吗?

提前致谢

【问题讨论】:

标签: iphone uiimage nsdata mkmapview


【解决方案1】:

为什么不尝试这样的事情(未经测试)?

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

NSData *mapData = UIImagePNGRepresentation(mapImage);
[mapData writeToFile:[self myFilePath:@"yourMap.png"] atomically:YES];

【讨论】:

  • 这是我希望我可以两次投票的情况之一。
猜你喜欢
  • 1970-01-01
  • 2013-10-02
  • 2017-03-24
  • 2014-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-23
  • 1970-01-01
相关资源
最近更新 更多