2012-05-02 125 views
0

在我的应用程序,我得到以下错误控制台:CGContextAddPath控制台错误?

May 1 22:06:59 iPhone-4S app[93660] <Error>: CGContextAddPath: invalid context 0x0 
May 1 22:06:59 iPhone-4S app[93660] <Error>: clip: invalid context 0x0 

在这可以发生在以下两种方法来调整或圆边添加到一个UIImage的唯一地区。下面是方法:

- (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize { 
    // Create a graphics image context 
    UIGraphicsBeginImageContext(newSize); 

    // Tell the old image to draw in this new context, with the desired 
    // new size 
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; 

    // Get the new image from the context 
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); 

    // End the context 
    UIGraphicsEndImageContext(); 

    // Return the new image. 
    return newImage; 
} 

- (UIImage*)roundCorneredImage: (UIImage*)orig radius:(CGFloat) r { 
    UIGraphicsBeginImageContextWithOptions(orig.size, NO, 0); 
    [[UIBezierPath bezierPathWithRoundedRect:(CGRect){CGPointZero, orig.size} 
           cornerRadius:r] addClip]; 
    [orig drawInRect:(CGRect){CGPointZero, orig.size}]; 
    UIImage* result = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return result; 
} 

这两种方法都是从UIViewControllers内打电话,我肯定的UIImage的不是零。

这是否有任何理由发生?

谢谢!

回答

6

确保上下文大小不为零。

+0

你的意思是我加入它的CGSize和/或半径参数? –

+0

是的,如果你调用UIGraphicsBeginImageContextWithOptions与零大小,你会得到完全相同的错误,所以我认为你的上下文是空的。 –