我不是想在一个组件上绘图,我只是想创建一个新的上下文(我认为)并吐出一个 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:无效上下文等...