MPMoviePlayerController

MPMoviePlayerController

本文介绍了有什么方法可以在MPMoviePlayerController播放时截取屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下步骤来捕获屏幕截图,但获得了MPMoviePlayerController的黑色背景

I tried below steps to capture screenshot but got black backround for 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;
}


推荐答案

获取 来自 MPMoviePlayerController 这样 按钮

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

编辑合并 images 作为从 MPMoviePlayerController 获取的一张图片,带有 ScreenShot 取自 UIWindow

EDIT : Merge both images as one image taken from MPMoviePlayerController with the ScreenShot taken from UIWindow.

参考链接用于合并。

Refer ios-merging-two-images-of-different-size link for merging.

这篇关于有什么方法可以在MPMoviePlayerController播放时截取屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!