10
我收到一些與UIView
中的UIImage
有關的問題。我有時(但並非總是)看到錯誤<Error>:CGContextSaveGState:無效的上下文0x0錯誤
<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;
}
另外,儘量跟蹤類那是呈現這個錯誤,看看有些對象沒有大小或框架。 – 2014-12-05 14:38:31