2012-12-13 80 views
3

我尝试下面的步骤来捕捉屏幕截图,但得到的黑色底色为的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; 
} 

回答

2

得到imageMPMoviePlayerController这样的actionbutton的:

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

编辑Mergeimages作为一个图像取自MPMoviePlayerControllerScreenShot取自UIWindow

请参阅ios-merging-two-images-of-different-size链接进行合并。

+0

但是,它只会给出MPMoviePlayerController的缩略图。在MPMoviePlayerController屏幕上还有其他元素,我想一次捕获所有元素。 –

+0

此方法现在已被弃用,请改用什么? – Stas

+0

@Stas我相信现在使用正确的方法是'requestThumbnailImagesAtTimes'。 – Gordonium

相关问题