gpt4 book ai didi

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

转载 作者:技术小花猫 更新时间:2023-10-29 11:06:09 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com