ios - 有没有办法在 MPMoviePlayerController 播放时截图

标签 ios xcode mpmovieplayercontroller screenshot capture

我尝试了以下步骤来捕获屏幕截图,但 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获取image,就像在按钮action上一样:

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

编辑:合并两个图像作为从MPMoviePlayerControllerScreenShot获取的一张图像code> 取自 UIWindow

引用ios-merging-two-images-of-different-size合并链接。

关于ios - 有没有办法在 MPMoviePlayerController 播放时截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13855340/

相关文章:

iphone - uiimageview的长按手势和移动?

ios - swift 3 此类对于键 startDate 不符合键值编码

ios - 为什么 UIAlertController 会用 self 创建一个保留周期?

ios - 是否有回调/代表告诉设备在离线后重新连接(到运营商服务或 wifi)?

xcode - SVN使用Xcode 4忽略模式

swift - 为 `swift package generate-xcodeproj` 设置 macOS 目标?

ios - xcodebuild [MT] iPhoneSimulator : Could not launch simulator: -600

swift - 来自 MPMoviePlayerController 的音频在转至下一个 View Controller 后继续播放

ios - 如何使用自定义 NSURLProtocol 播放带 URL 的电影?

ios - 模拟器不播放视频