iPhone和iPad,播放视频时截图
我的应用程序需要在屏幕上播放视频时截取一些屏幕截图。视频由AVPlayer和AVPlayerLayer播放。当我尝试使用旧方法时出现的问题,例如:
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;
它返回屏幕图像和黑色区域(视频应该在那里)。我可以使用 UIGetScreenImage() 成功截取屏幕截图,但它是一个私有 API,所以我不确定是否可以使用它
My app need to take some screenshot when a video is being played on the screen. The video is played by AVPlayer and 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,许多已发布的应用程序一直在使用
UIGetScreenImage()
。看来苹果对它的使用相当宽松。或许你可以抓住机会...From what I have read, many published apps have been using
UIGetScreenImage()
. It seems like Apple is quite lenient with its usage. Perhaps you could take a chance...尽管已经过去了很多时间 - 我想指出现在可以在 iOS 7 上使用 UIView 上的快照命令:
https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/snapshotViewAfterScreenUpdates:
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:
https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/snapshotViewAfterScreenUpdates: