我正在尝试添加一个png图像作为一个自定义地图使用MKOverlayView。我就快完成了-我能够将图像排列在正确的位置,并且我知道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);有人知道这是怎么回事吗?
谢谢!-Matt
发布于 2010-11-26 21:59:45
我也遇到过类似的问题。问题是我的boundingMapRect定义不正确。当平铺上的比例较小时,整个图像将按比例进行渲染。然后缩放地图,并不是所有的图像瓦片都在boundingMapRect瓦片中,因此它们不会以正确的比例重新绘制,缩小的版本将被缩放。至少我是这么认为的。
希望这能有所帮助。
发布于 2011-01-13 18:19:22
去掉CGContextScaleCTM(context,1.0,-1.0);并在预览中对图像进行垂直翻转。mapkit似乎使用上下文信息来确定要更清晰地呈现图像的哪个部分。我知道这已经有一段时间了,但希望它能有所帮助!
发布于 2016-11-28 05:18:16
谢谢Rob,你让我很开心。当我更换时,我的模糊叠加图像变得清晰了
CGContextScaleCTM(context, 1.0, -1.0);使用
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, theRect.size.height);
CGContextConcatCTM(context, flipVertical); https://stackoverflow.com/questions/4117182
复制相似问题