iphone - <错误> : CGContextSaveGState: invalid context 0x0 Error

标签 iphone ios uiview cgcontext

我遇到了一些与从 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/

相关文章:

iphone - 在 PopOverController 的帮助下填充表 - Objective C

iphone - 在 iTunes Connect 中,为什么分发证书已经存在?

uiview - AdMob GADBannerView 在不应该发布和接收广告请求时未发布和接收广告请求

ios - 为什么刷新某些行后 TableView 单元格会困惑?

android - 为什么自定义图标在手机上显示不正确?

ios - 在 iOS 应用程序中获取 WAN IP

ios - sqlite3.dylib : illegal multi-threaded access to database connection

ios - swift 地,我如何以编程方式制作 View 层?

ios - 重用 UI(xib 文件)

ios - 在 UIImageView IOS 上画圆的最佳方法