[英]How to get iphone device screenshot when image animation is run on main thread?
我正在执行图像序列动画是在主线程上。 同时我想在后台拍摄设备屏幕的快照。 通过使用我想制作视频的快照..
谢谢,Keyur Prajapati
用于在运行图像动画时截取屏幕截图
使用
[self.view.layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];
代替
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
在运行动画时会截取屏幕截图
iOS使用Core Animation作为渲染系统。 每个UIView都有一个CALayer支持。 每个可见层树都由表示树支持。 图层树包含每个图层的对象模型值,即您为图层属性(A和B)指定值时设置的值。 表示树包含当动画发生时当前呈现给用户的值(A和B之间的插值)。
如果您在CoreAnimation中执行此操作,则可以使用-renderInContext:
将层内容呈现为位图-renderInContext:
。 看看Matt Longs 教程 。 它适用于Mac上的Objective-C,但可以轻松转换为在iPhone上使用。
创建另一个线程,您可以在其中执行此操作:
//Create rect portion for image if full screen then 320X480
CGRect contextRect = CGRectMake(0, 0, 320, 480);
// this is whate you need
UIGraphicsBeginImageContext(contextRect.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
viewImage是您需要的图像。
您可以在函数中编写此代码,可以按照5秒或根据您的要求及时调用。
希望这是你需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.