2012-06-29 119 views
3

我在玩MPMoviePlayerController.Perfectly時截屏,保存屏幕截圖,但圖像只有黑色。我使用下面的代碼。MPMoviePlayerController拍攝屏幕截圖,但只顯示黑屏

UIGraphicsBeginImageContext(self.moviePlayerController.view.frame.size); 
[self.moviePlayerController.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 

回答

0

您可以用MPMoviePlayerControllerthumbnailImageAtTime方法試試。

UIImage *aThumbnail = [player thumbnailImageAtTime:timeCode timeOption:MPMovieTimeOptionExact]; 
//timeCode is a time within the video length, for example: 5 seconds. 
+0

謝謝...但沒有任何反應UIGraphicsBeginImageContext(個體經營.movi​​ePlayerController.view.frame.size); [self.movi​​ePlayerController.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIGraphicsEndImageContext(); UIImage * aThumbnail = [self.movi​​ePlayerController thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionExact]; UIImageWriteToSavedPhotosAlbum(aThumbnail,nil,nil,nil);我用這條線。 –

3

最後我解決了這個問題......我用這個代碼...完美的工作......感謝所有...

- (void)captureScreenShot 
{ 
    CGImageRef originalImage = UIGetScreenImage(); 
    CGImageRef videoImage = CGImageCreateWithImageInRect(originalImage, CGRectMake(0, 66, 320, 230));    
    UIImage *snapShotImage = [UIImage imageWithCGImage:videoImage]; 
    UIImageWriteToSavedPhotosAlbum(snapShotImage, nil, nil, nil); 
    CGImageRelease(originalImage);     
    CGImageRelease(videoImage); 
}