2010-12-22 17 views
10

Estoy obteniendo un problema relacionado con la preparación de UIImage de un UIView. A veces (pero no siempre) veo el error<Error>: CGContextSaveGState: contexto no válido 0x0 Error

<Error>: CGContextSaveGState: invalid context 0x0 

Estoy usando el iPhone SDK 4.0. Mi código:

-(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; 
} 

Respuesta

4

El error <Error>: CGContextSaveGState: invalid context 0x0 significa o bien su CGContext es nulo o, la explicación más razonable en su caso, que el tamaño del Contexto está vacía (CGSizeZero)

+0

Además, trate de realizar un seguimiento de la clase eso es presentar este error y ver si algún objeto no tiene tamaño o marco. –

Cuestiones relacionadas