<error>:CGContextSaveGState:无效的上下文0x0错误</error>

时间:2010-12-22 12:50:09

标签: iphone ios uiview cgcontext

我收到了与UIImage中的UIView相关的问题。我有时(但不总是)看到错误

<Error>: CGContextSaveGState: invalid context 0x0

我正在使用iPhone SDK 4.0。我的代码:

-(void)drawRect:(CGRect)rect
{
     // Customized to draw some text
}


-(UIImage*) PrepareBackImage:(CGRect) aRect // aRect = (0,0,1800,1200)
{
    UIImage* background;

    background      = [self GetImageFromView:self toRect:self.frame];
    UIGraphicsBeginImageContext(aRect.size);

    CGPoint backgroundPoint = CGPointMake(0,0);
    [background drawAtPoint:backgroundPoint];

    UIImage* backImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return backImage;
}

- (UIImage *) GetImageFromView:(UIView *)aView toRect:(CGRect)aRect
{
    CGSize pageSize = aRect.size;
    UIGraphicsBeginImageContext(pageSize);
    [aView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

1 个答案:

答案 0 :(得分:4)

错误<Error>: CGContextSaveGState: invalid context 0x0表示您的CGContext为NULL,或者在您的情况下更合理的解释,即Context的大小为空(CGSizeZero

相关问题