我尝试了以下步骤来捕获屏幕截图,但 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];
}
编辑:合并
两个图像
作为从MPMoviePlayerController
与ScreenShot
获取的一张图像code> 取自 UIWindow
。
关于ios - 有没有办法在 MPMoviePlayerController 播放时截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13855340/