开发者

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. 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 mainSc开发者_StackOverflow社区reen].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


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...


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:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜