【问题标题】:MKOverlay View is blurredMKOverlay 视图模糊
【发布时间】:2010-11-07 09:35:36
【问题描述】:

我正在尝试使用 MKOverlayView 将 png 图像添加为自定义地图。我快到了 - 我能够将图像排列在正确的位置,并且我知道 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);

有人知道发生了什么吗?

谢谢! -马特

【问题讨论】:

  • 图像的内容是否正确地缩放到地图的内容?
  • 虽然我在这里的代码没有反映它,但我将叠加层的边界设置为图像本身的大小 - 奇怪的是它似乎只是想重绘地图地图的左下角。在那个地区,它看起来或多或少还可以。

标签: iphone core-graphics mkmapview overlay cgimage


【解决方案1】:

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

希望这会有所帮助。

【讨论】:

  • 好的,谢谢。原来我的图像使用了错误的纵横比。
【解决方案2】:

摆脱CGContextScaleCTM(context, 1.0, -1.0);并在预览中对您的图像进行垂直翻转。 mapkit 似乎使用上下文信息来确定要更清晰地渲染图像的哪个部分。知道已经有一段时间了,但希望对您有所帮助!

【讨论】:

  • 感谢您的回答。我遇到了与@mag725 相同的问题。它解决了我的问题。
【解决方案3】:

谢谢 Rob,你让我开心。替换后,我的模糊叠加图像变得清晰

CGContextScaleCTM(context, 1.0, -1.0);

CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, theRect.size.height);
CGContextConcatCTM(context, flipVertical);  

【讨论】:

    猜你喜欢
    • 2016-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多