我有下面的方法,我试着在图像中进行一些绘制:
- (UIImage*) renderImage
{
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
//drawing code
UIImage *image = [UIGraphicsGetImageFromCurrentImageContext() retain];
UIGraphicsEndImageContext();
return [image autorelease];
}当我运行这段代码时,我注意到我受到的冲击比我在UIView的drawRect中简单地绘制这段代码时受到的打击要大得多。我是不是进入了错误的图形环境(如CGContextRef context = UIGraphicsGetCurrentContext();)?或者,UIGraphicsGetImageFromCurrentImageContext比在drawRect中绘图要昂贵得多
发布于 2012-11-01 19:00:09
主要区别在于,您创建的上下文需要屏幕外渲染,它与在-drawRect中创建的上下文不同。因此,您向堆中添加了一个额外的内存,直到您释放映像为止。
https://stackoverflow.com/questions/13173933
复制相似问题