MPMoviePlayerController 截屏但只显示黑屏
Posted
技术标签:
【中文标题】MPMoviePlayerController 截屏但只显示黑屏【英文标题】:MPMoviePlayerController Taking screen shot but showing only black screen 【发布时间】:2012-06-29 08:52:10 【问题描述】:我在播放 MPMoviePlayerController 时截屏。完美保存屏幕截图,但图像只有黑色。我使用下面的代码。
UIGraphicsBeginImageContext(self.moviePlayerController.view.frame.size);
[self.moviePlayerController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
【问题讨论】:
【参考方案1】:最后我解决了这个问题...我正在使用此代码...完美运行...感谢所有人...
- (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);
【讨论】:
【参考方案2】:你可以试试MPMoviePlayerController
的thumbnailImageAtTime
方法。
UIImage *aThumbnail = [player thumbnailImageAtTime:timeCode timeOption:MPMovieTimeOptionExact];
//timeCode is a time within the video length, for example: 5 seconds.
【讨论】:
谢谢...但是什么也没发生 UIGraphicsBeginImageContext(self.moviePlayerController.view.frame.size); [self.moviePlayerController.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIGraphicsEndImageContext(); UIImage *aThumbnail = [self.moviePlayerController thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionExact]; UIImageWriteToSavedPhotosAlbum(aThumbnail, nil, nil, nil);我用这条线。以上是关于MPMoviePlayerController 截屏但只显示黑屏的主要内容,如果未能解决你的问题,请参考以下文章
如何显示 MPMoviePlayerController 控件?
MPMoviePlayerController 隐藏 AirPlay 按钮
MPMoviePlayerController 上的专辑封面
MPMoviePlayerController 已弃用,现在怎么办?