私は単に新しいコンテキストを作成しようとしているコンポーネントを描画しようとしているのではなく (私は思う)、描画の内容を含む UIImage を吐き出そうとしています。既存のコンポーネントを描画しようとしているわけではありません。次のコードを使用しています。
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, self.textSize.width, self.textSize.height, 8, 4 * self.textSize.width,
colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1);
NSString *text = @"Hello world";
[text drawAtPoint:CGPointMake(0, 0) forWidth:maxWidth withFont:font lineBreakMode:UILineBreakModeWordWrap];
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
UIImage * myRendering = [UIImage imageWithCGImage:imageMasked];
残念ながら、「無効なコンテキスト」というエラー メッセージが表示されます。Google で検索しても、既存のコンポーネントを利用しようとしている人しか出てこなかったようです。新しいUIImageを吐き出したい。
ビットマップコンテキストを作成するために、ここで例を試しました - http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_context/dq_context.html#//apple_ref/doc/uid/TP30001066-CH203 -SW9
私はまだ得る:
: CGContextGetShouldSmoothFonts: 無効なコンテキスト : CGContextSetFont: 無効なコンテキスト : CGContextSetTextMatrix: 無効なコンテキスト : CGContextSetFontSize: 無効なコンテキスト など...