我遇到了一些与从 UIView
中准备 UIImage
有关的问题。我有时(但不总是)看到错误
<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;
}
最佳答案
错误 <Error>: CGContextSaveGState: invalid context 0x0
表示您的 CGContext 为 NULL,或者在您的情况下更合理的解释是 Context 的大小为空(CGSizeZero
)
关于iphone - <错误> : CGContextSaveGState: invalid context 0x0 Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4509324/