Ios 当MPMoviePlayerController正在播放时,有没有办法拍摄屏幕截图
我尝试了以下步骤来捕捉截图,但MPMoviePlayerController却遇到了黑色背景Ios 当MPMoviePlayerController正在播放时,有没有办法拍摄屏幕截图,ios,xcode,mpmovieplayercontroller,screenshot,capture,Ios,Xcode,Mpmovieplayercontroller,Screenshot,Capture,我尝试了以下步骤来捕捉截图,但MPMoviePlayerController却遇到了黑色背景 -(UIImage*)screenshot { CGSize imageSize = [[UIScreen mainScreen] bounds].size; CGFloat imageScale = imageSize.width / FRAME_WIDTH; if (NULL != UIGraphicsBeginImageContextWithOptions) UIGraphicsBe
-(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];
}
编辑:合并
两个图像
作为从MPMoviePlayerController
拍摄的一个图像,使用屏幕截图
从ui窗口
拍摄
请参阅合并链接。但是,它只提供MPMoviePlayerController的缩略图。使用MPMoviePlayerController,屏幕上还有其他元素,我希望一次捕获所有元素。现在不推荐使用此方法,改用什么?@Stas我认为现在使用的正确方法是requestThumbnailImagesAtTimes
。