【发布时间】:2013-04-24 11:31:37
【问题描述】:
我正在使用上一个答案中的以下代码通过组合 UIImageView 和 UITextView 创建新的 UIImage。
UIView *parentView = [[UIView alloc] initWithFrame:CGRectZero];
[parentView addSubview:self.imagePreview];
[self.imagePreview setFrame:CGRectMake(0, 0, 100, 100)];
[parentView addSubview:self.memeTextFieldTop];
[self.memeTextFieldTop setFrame:CGRectMake(20, 20, 80, 20)];
[parentView sizeToFit];
UIGraphicsBeginImageContext([parentView bounds].size);
[[parentView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
问题似乎是我目前遇到以下错误,我不确定如何解决这些错误。
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextSetAlpha: invalid context 0x0
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextGetBaseCTM: invalid context 0x0
<Error>: CGContextConcatCTM: invalid context 0x0
<Error>: CGContextSetBaseCTM: invalid context 0x0
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextSetAlpha: invalid context 0x0
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextConcatCTM: invalid context 0x0
任何想法如何解决这个问题?
【问题讨论】:
-
我看到你做了 [parentView sizeToFit];你确定框架不是 CGRectZero 吗?
-
那是因为 parentView 帧大小仍然为零。使用 NSLog 检查框架。
标签: ios objective-c uigraphicscontext