有人能帮我吗?我想从一个通过MPMediaPlayerController播放的视频中得到一个截图。到目前为止,我尝试的是:-
-(void)viewDidLoad
{
NSURL *tempFilePathURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"LMFao" ofType:@"mp4"]];
player = [[MPMoviePlayerController alloc] initWithContentURL:tempFilePathURL];
[player setControlStyle:MPMovieControlStyleFullscreen];
//Place it in subview, else it won’t work
player.view.frame = CGRectMake(0, 0, 320, 400);
[self.view addSubview:player.view];
}
-(IBAction)screenshot
{
CGRect rect = [player.view bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[player.view.layer renderInContext:context];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(150, 150, 100, 100)];
[imgView setImage:image];
imgView.layer.borderWidth = 2.0;
[self.view addSubview:imgView];
}我现在得到的是:-

现在发生的是我的播放器的按钮在ScreenShot中被捕获,但是我的视频的图像没有被捕获。我使用这个上下文方法来捕获我的图像,因为我在我的视频上有一个覆盖层,使用缩略图方法我不能用覆盖来捕获视频,但是我想获得带有覆盖层的视频图像。
编辑:我想要的是获得这段视频的屏幕截图和这张图片中所示的覆盖图

但是我得到的是一种方法--我只有一种方法--在我的屏幕截图中只得到视频而不是覆盖--我的方法是缩略图法,我用的是缩略图法,第二种方法是MPMoviePlayerController给出的方法,第二种方法是在屏幕截图中只得到一段视频,这个方法是上下文方法。我正在获取rect.Now的上下文,我认为解决方案可能是把这两种方法结合在一起,通过给出建议,合并图像对我有用吗?
请help.Thanks :)
发布于 2012-05-15 09:35:11
U可以合并来自这个way.Please的两个图像,请看下面的代码。
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {
MaskView=[[UIView alloc] init];
UIImageView *image1=[[UIImageView alloc]init];
UIImageView *image2=[[UIImageView alloc]init];
MaskView.frame=CGRectMake(0, 0,500,500);
image1.frame=CGRectMake(0,0,160, 160);
image2.frame=CGRectMake(60,54,40,40);
image1.image=image;
image2.image=maskImage;
[MaskView addSubview:image1];
[MaskView addSubview:image2];
UIGraphicsBeginImageContext(CGSizeMake(160,160));
[MaskView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *finishedPic = UIGraphicsGetImageFromCurrentImageContext();
return finishedPic;
}发布于 2012-05-14 12:39:42
您只需在mpmovieplayer对象上调用一个方法:
- (UIImage *)thumbnailImageAtTime:(NSTimeInterval)playbackTime timeOption:(MPMovieTimeOption)option
此方法将返回一个UIImage对象。你要做的就是:
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];有关更多详细信息,请参阅MPMoviePlayerController
希望这能有所帮助
编辑:在您的方法中,您可以先隐藏播放机的控件,然后再显示控件之后再捕获图像。您可以使用controlStyle属性MPMoviePlayerController来实现这一点。
不确定这是你要找的,但这是我所理解的。如果你在寻找不同的东西,请告诉我。
发布于 2012-05-14 12:36:08
这可能会有帮助
- (UIImage *)thumbnailImageAtTime:(NSTimeInterval)playbackTime timeOption:(MPMovieTimeOption)option在给定的时间和比例上获取thumbnailImage图像。
https://stackoverflow.com/questions/10582943
复制相似问题