iphone - MKOverlay View 模糊

标签 iphone core-graphics mkmapview overlay cgimage

我正在尝试使用 MKOverlayView 添加 png 图像作为自定义 map 。我几乎就在那里 - 我能够将图像排列在正确的位置,并且我知道 MKOverlayView 子类中的 -drawMapRect: 方法正在被定期调用;我似乎无法正确渲染图像。完全模糊了,几乎认不出来了。我也知道图像足够大(1936 × 2967)。这是我的 -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);

有人知道发生了什么事吗?

谢谢! -马特

最佳答案

我也遇到过类似的问题。问题是我的boundingMapRect定义不正确。当图 block 上的比例较小时,完整图像会按比例缩小呈现。然后 map 被缩放,并且并非所有图像图 block 都在boundingMapRect图 block 中,因此它们不会以正确的比例重新绘制,并且缩小的版本被缩放。至少我认为是这样。

希望这有帮助。

关于iphone - MKOverlay View 模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4117182/

相关文章:

iphone - 尝试在没有 NIB 的情况下在 View 中显示 UILabel

iphone - 如何使用 iOS 登录网站

ios - CGContextDrawImage 在传递 UIImage.CGImage 时颠倒绘制图像

ios - 如何在 Swift 4 中设置 QRCode 版本

ios - 如何显示通过 plist 加载的多个自定义注释(图钉和左图标)?

ios - 键盘上方的工具栏未显示在 -- iOS 11 上

android - 从桌面以移动方式查看网站

c# - MonoTouch.Dialog:节标题 View 中颠倒的文本

iphone - 如何从 JSON 输出中分离纬度和经度值?

ios - 将事件传递到另一个 View