我正在尝试使用 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/