MKOverlay视图模糊不清 [英] MKOverlay View is blurred

查看:148
本文介绍了MKOverlay视图模糊不清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MKOverlayView将png图像添加为自定义地图。我几乎就在那里 - 我能够将图像排列在正确的位置,我知道MKOverlayView的子类中的-drawMapRect:方法是定期调用的;我似乎无法让图像正确渲染。它完全模糊,几乎无法辨认。我也知道图像足够大(它是1936×2967)。这是我的-drawMapRect代码:

I'm trying to add a png image as a custom map using MKOverlayView. I'm almost there - I am able to get the image lined up in the right place, and I know that the -drawMapRect: method in the subclass of MKOverlayView is being called periodically; I just can't seem to get the image to render properly. It's totally blurry, almost beyond recognition. I also know the image is large enough (it is 1936 × 2967). Here is my code for -drawMapRect:

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context{


    // Load image from applicaiton bundle
    NSString* imageFileName = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"map.jpg"];
    CGDataProviderRef provider = CGDataProviderCreateWithFilename([imageFileName UTF8String]);
    CGImageRef image = CGImageCreateWithJPEGDataProvider(provider, NULL, true, kCGRenderingIntentDefault);
    CGDataProviderRelease(provider);

    // save context before screwing with it
    CGContextSaveGState(context);
    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextSetAlpha(context, 1.0);

    // get the overlay bounds
    MKMapRect theMapRect = [self.overlay boundingMapRect];
    CGRect theRect = [self rectForMapRect:theMapRect];

    // Draw image
    CGContextDrawImage(context, theRect, image);
    CGImageRelease(image);
    CGContextRestoreGState(context);

有没有人知道发生了什么?

Does anyone have a clue what's going on?

谢谢!
-Matt

Thanks! -Matt

推荐答案

我遇到了类似的问题。问题是我的boundingMapRect定义不正确。当图块上的比例较小时,将缩小整个图像。然后缩放地图,并且并非所有图像切片都位于boundingMapRect切片中,因此不会以正确的比例重新绘制它们,并缩小缩小的版本。至少这就是我认为的情况。

I've had a similar problem. The problem was that my boundingMapRect was defined incorrectly. The full image is rendered scaled down when the scale is small on a tile. Then the map is zoomed and not all the image tiles are in the boundingMapRect tiles so they are not redrawn in the correct scale and the scaled down version is zoomed. At least that's what I think happens.

希望这会有所帮助。

这篇关于MKOverlay视图模糊不清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆