MPMoviePlayerController播放时有没有办法截屏?

3
我尝试了以下步骤来截取屏幕截图,但在MPMoviePlayerController中得到了黑色背景。
-(UIImage*)screenshot
{
 CGSize imageSize = [[UIScreen mainScreen] bounds].size;

CGFloat imageScale = imageSize.width / FRAME_WIDTH;

if (NULL != UIGraphicsBeginImageContextWithOptions)
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, imageScale);
else
    UIGraphicsBeginImageContext(imageSize);

CGContextRef context = UIGraphicsGetCurrentContext();

for (UIWindow *window in [[UIApplication sharedApplication] windows]) 
{
    if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
    {
        CGContextSaveGState(context);

        CGContextTranslateCTM(context, [window center].x, [window center].y);

        CGContextConcatCTM(context, [window transform]);

        CGContextTranslateCTM(context,
                              -[window bounds].size.width * [[window layer] anchorPoint].x,
                              -[window bounds].size.height * [[window layer] anchorPoint].y);

        [[window layer] renderInContext:context];

        CGContextRestoreGState(context);
    }
}

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;
}
1个回答

2

buttonaction中,可以像这样从MPMoviePlayerController获取image

-(void)getScreenShotOfMPMoviePlayerController:(MPMoviePlayerController *)mpPlayer
{
   UIImage *thumbnail = [mpPlayer thumbnailImageAtTime:yourMoviePlayerObject.currentPlaybackTime 
                       timeOption:MPMovieTimeOptionNearestKeyFrame];
}

编辑:将从MPMoviePlayerController获取的image和从UIWindow获取的ScreenShot合并为一张图片。

请参考ios-merging-two-images-of-different-size链接进行合并。


但是,它只会给出MPMoviePlayerController的缩略图。我屏幕上还有其他元素与MPMoviePlayerController一起,我想一次性捕获它们所有。 - Rahul Gupta
这个方法现在已经被弃用了,应该使用什么替代? - Stas
@Stas 我相信现在应该使用的正确方法是 requestThumbnailImagesAtTimes - Gordonium

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接