我使用以前的答案中的以下代碼通過組合UIImageView和UITextView來創建新的UIImage。從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嗎? – 2013-04-24 11:35:54
多數民衆贊成在'因爲parentView框架大小仍然爲零。用NSLog檢查框架。 – x4h1d 2013-04-24 11:46:20