以真实分辨率将 MKMapView 渲染为 UIImage
我正在使用此函数将 MKMapView 实例渲染为图像:
@implementation UIView (Ext)
- (UIImage*) renderToImage
{
UIGraphicsBeginImageContext(self.frame.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
这工作正常。但对于 iphone4,渲染图像的分辨率与设备上实际的分辨率不同。在设备上,我的地图视图质量为 640x920,渲染图像的分辨率为 320x460。 然后,我将提供给 UIGraphicsBeginImageContext() 函数的大小加倍,但填充了唯一的左上角图像部分。
问题:有什么方法可以将地图渲染为全分辨率 640x920 的图像吗?
I am using this function for rendering MKMapView instance into image:
@implementation UIView (Ext)
- (UIImage*) renderToImage
{
UIGraphicsBeginImageContext(self.frame.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
This works fine. But with iphone4 the rendered image doesn't have same resolution as it has really on device. On device I have the 640x920 map view quality, and rendered image has the resolution 320x460.
Then I doubled the size that is provided to UIGraphicsBeginImageContext() function but that filled the only top-left image part.
Question: Is there any way to get map rendered to image with full resolution 640x920?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
iOS 7 引入了一种新方法来生成 MKMapView 的屏幕截图。现在可以使用新的 MKMapSnapshot API,如下所示:
目前,所有叠加层和注释均未渲染。之后您必须自己将它们渲染到生成的快照图像上。提供的 MKMapSnapshot 对象有一个方便的辅助方法来完成坐标和点之间的映射:
iOS 7 introduced a new method to generate screenshots of a MKMapView. It is now possible to use the new MKMapSnapshot API as follows:
Currently all overlays and annotations are not rendered. You have to render them afterwards onto the resulting snapshot image yourself. The provided MKMapSnapshot object has a handy helper method to do the mapping between coordinates and points:
尝试使用
UIGraphicsBeginImageContextWithOptions
而不是UIGraphicsBeginImageContext
:请参阅 QA1703 了解更多详情。它说:
Try using
UIGraphicsBeginImageContextWithOptions
instead ofUIGraphicsBeginImageContext
:See QA1703 for more details. It says: