iPhone和iPad,播放视频时截图

发布于 2024-12-07 20:58:48 字数 704 浏览 0 评论 0原文

我的应用程序需要在屏幕上播放视频时截取一些屏幕截图。视频由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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

合久必婚 2024-12-14 20:58:48

据我所知,许多已发布的应用程序一直在使用 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...

不爱素颜 2024-12-14 20:58:48

尽管已经过去了很多时间 - 我想指出现在可以在 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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文