首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKOverlay视图模糊

MKOverlay视图模糊
EN

Stack Overflow用户
提问于 2010-11-07 17:35:36
回答 3查看 1.5K关注 0票数 2

我正在尝试添加一个png图像作为一个自定义地图使用MKOverlayView。我就快完成了-我能够将图像排列在正确的位置,并且我知道MKOverlayView的子类中的-drawMapRect:方法会被定期调用;我只是看起来无法正确地呈现图像。它是完全模糊的,几乎无法辨认。我也知道图像足够大(它是1936 × 2967)。下面是我的-drawMapRect代码:

代码语言:javascript
复制
- (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);

有人知道这是怎么回事吗?

谢谢!-Matt

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-11-26 21:59:45

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

希望这能有所帮助。

票数 4
EN

Stack Overflow用户

发布于 2011-01-13 18:19:22

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

票数 2
EN

Stack Overflow用户

发布于 2016-11-28 05:18:16

谢谢Rob,你让我很开心。当我更换时,我的模糊叠加图像变得清晰了

代码语言:javascript
复制
CGContextScaleCTM(context, 1.0, -1.0);

使用

代码语言:javascript
复制
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, theRect.size.height);
CGContextConcatCTM(context, flipVertical);  
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4117182

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档