[英]iPhone and iPad, take screenshot with video playing
My app need to take some screenshot when a video is being played on the screen. 在屏幕上播放视频时,我的应用需要截取一些屏幕截图。 The video is played by AVPlayer and AVPlayerLayer.
该视频由AVPlayer和AVPlayerLayer播放。 The problem when I try to use old methods, such as:
当我尝试使用旧方法时的问题,例如:
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
CGRect rect = [keyWindow bounds];
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[keyWindow.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
It returns an image of the screen and a black area (which the video should be there). 它返回屏幕图像和黑色区域(视频应该在该区域)。 I can take a screenshot successfully with UIGetScreenImage() but it is a private API so I am not sure if I can use it or not
我可以使用UIGetScreenImage()成功拍摄屏幕截图,但这是一个私有API,所以我不确定是否可以使用它
From what I have read, many published apps have been using UIGetScreenImage()
. 据我了解,许多已发布的应用程序一直在使用
UIGetScreenImage()
。 It seems like Apple is quite lenient with its usage. 看起来苹果公司对它的用法相当宽容。 Perhaps you could take a chance...
也许您可以借此机会...
Although a lot of time has passed - I would like to note this is now possible on iOS 7 using the snapshot command on a UIView: 尽管已经过去了很多时间-我想指出的是,现在可以在iOS 7上使用UIView上的snapshot命令:
https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/snapshotViewAfterScreenUpdates : https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/snapshotViewAfterScreenUpdates :
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.