2012-12-13 79 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

相關問題