0

我有一个由 CATiledLayer 支持的 UIScrollView。该层正在从服务器中提取切片并显示它们以响应调用时的请求drawLayer:inContext。这是它的样子:

-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{
    ASIHTTPRequest *mapRequest;
    WMSServer *root = self.mapLayer.parentServer;
    while(root == nil){
        root = self.mapLayer.parentLayer.parentServer;
    }
    //Get where we're drawing
    CGRect clipBox = CGContextGetClipBoundingBox(ctx);
    double minX = CGRectGetMaxY(clipBox);
    double minY = CGRectGetMinX(clipBox);
    double maxX = CGRectGetMinY(clipBox);
    double maxY = CGRectGetMaxX(clipBox);

    //URL for the request made here using the min/max values from above
    NSURL *url = [[NSURL alloc] initWithString:path];
    mapRequest = [ASIHTTPRequest requestWithURL:url];
    [url release];
    [mapRequest startSynchronous];
    //Wait for it to come back...
    //Turn the Data into an image
    NSData *response = [mapRequest responseData];
    //Create the entire image
    CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((CFDataRef)response);
    CGImageRef image = CGImageCreateWithPNGDataProvider(dataProvider, NULL, true, kCGRenderingIntentDefault);
    CGDataProviderRelease(dataProvider);
    //Now paint the PNG on the context
    CGContextDrawImage(ctx, clipBox, image);
}

当我放大时会出现问题。图块的大小(如clipBox矩形所示)缩小了,如果是 32 x 32 像素,则 URL 的格式正确为 32 像素,但屏幕上显示的内容会缩放直到默认的 tileSize(在这种情况下为 128 x 128 像素)。有什么方法可以让图层正确绘制这些图像。

4

1 回答 1

0

找到了。获取CGAffineTransformwith CGContextGetCTM(CGContextRef),并使用a(or b) 属性的值作为缩放。在适当缩放的屏幕分辨率中获取图像(将高度和宽度乘以缩放)。然后将该图像绘制到剪辑框中。

于 2010-06-08T14:50:50.043 回答