当MPMoviePlayerController正在播放的时候,有没有什么办法来截图
我尝试了下面的步骤捕捉屏幕截图,但得到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; }
从button
action
中像这样从MPMoviePlayerController
获取image
:
-(void)getScreenShotOfMPMoviePlayerController:(MPMoviePlayerController *)mpPlayer { UIImage *thumbnail = [mpPlayer thumbnailImageAtTime:yourMoviePlayerObject.currentPlaybackTime timeOption:MPMovieTimeOptionNearestKeyFrame]; }
编辑 : Merge
两个images
作为从UIWindow
采取的ScreenShot
从MPMoviePlayerController
采取一个图像。
请参阅ios-merge-two-images-of-size- link链接进行合并。