我想创建一个UIImage
来自MKMapView
.我的地图在视图中正确显示,但UIImage
生成的只是一个灰色图像.这是相关的片段.
UIGraphicsBeginImageContext(mapView.bounds.size);
[mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
mapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
有谁知道如何UIImage
使用MapKit?
我使用与ios sdk 4.1测试相同的代码并且工作正常.因此,当地图已经显示给用户并且用户按下按钮时,将调用此操作:
UIImage *image = [mapView renderToImage];
Run Code Online (Sandbox Code Playgroud)
这是作为UIView扩展实现的包装函数:
- (UIImage*) renderToImage
{
UIGraphicsBeginImageContext(self.frame.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Run Code Online (Sandbox Code Playgroud)
所以,问题不在于代码部分.
归档时间: |
|
查看次数: |
7965 次 |
最近记录: |