【发布时间】:2013-10-04 16:37:45
【问题描述】:
我正在制作放大镜应用程序,它允许用户触摸屏幕并移动他的手指,会有一个放大镜与他的手指路径。我通过截图来实现它并将图像分配给放大镜图像视图,如下所示:
CGSize imageSize = frame.size;
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextScaleCTM(c, scaleFactor, scaleFactor);
CGContextConcatCTM(c, CGAffineTransformMakeTranslation(-frame.origin.x, -frame.origin.y));
[self.layer renderInContext:c];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return screenshot;
问题是self.layer renderInContext很慢,所以用户在移动手指时感觉不流畅。我尝试在其他线程中运行self.layer renderInContext,但是,它使放大镜图像看起来很奇怪,因为放大镜中的图像显示延迟。
有没有更好的方法将视图渲染成图像? renderInContext: 使用 GPU 吗?
【问题讨论】:
-
回答你的问题,根据Polishing Your User Interface Rotations,
renderInContext是在CPU中执行的。
标签: ios ios6 uiview core-graphics calayer