无限源矩形到drawImage方法

时间:2010-08-18 10:45:03

标签: objective-c cocoa

为什么我总是得到这个日志Infinite source rectangle to drawImage method,这是一个错误还是代码算法有问题。我真的不明白这一点,我在谷歌上找不到任何有用的信息。希望我能在这个网站上找到答案。

抱歉,这是我的drawRect方法:

- (void)drawRect:(NSRect)rect {
    // Drawing code here.

    // drawBackground
    [[NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:1.0] set];
    [NSBezierPath fillRect:[self bounds]];

    if (myCIImage != nil) {

        //Create the CIContext
        CIContext *context =  [[NSGraphicsContext currentContext] CIContext];

        //scale to fit in view rect
        CIImage *drawnImage;
        if (previewFilter == YES) {
            drawnImage = [previewImage imageByApplyingTransform:[self imageTransformToFitView]];
        } else {
            drawnImage = [myCIImage imageByApplyingTransform:[self imageTransformToFitView]];
        }

        // center in view rect
        NSRect viewBounds = [self bounds];
        CGRect sRect = [drawnImage extent];
        CGRect dRect = sRect;
        dRect.origin.x = viewBounds.origin.x + (viewBounds.size.width - sRect.size.width)/2;
        dRect.origin.y = viewBounds.origin.y + (viewBounds.size.height - sRect.size.height)/2;


        [context drawImage:drawnImage
                    inRect:dRect
                  fromRect:sRect];

    }

}

谢谢 -

1 个答案:

答案 0 :(得分:1)

我认为这意味着sRect的维度包含一些无限数字。您是否在调试器下运行并检查了sRect中的值?

您应用于图像的转换可能是错误的。