如何通过iPhone中的MPMediaPlayerController播放视频截图? [英] How to take a screenshot from an video playing through MPMediaPlayerController in iPhone?

查看:152
本文介绍了如何通过iPhone中的MPMediaPlayerController播放视频截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我吗?我想从通过MPMediaPlayerController播放的视频中获取屏幕截图。我到目前为止尝试的是: -

Can anybody help me in this? I want to get an screenshot from an video playing through MPMediaPlayerController. What i have tried so far is:-

-(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];
}

我现在得到的是: -

And what i ve got now is this:-

现在发生的事情是我的播放器的按钮被截取在ScreenShot但我的视频图像没有得到。我正在使用这种上下文方法来捕捉我的图像,因为
i在我的视频上有一个叠加,使用缩略图方法我无法使用叠加功能捕捉视频,但我希望通过叠加功能获取视频图像。

what is happening now is my player's button are getting captured in ScreenShot but my video's image is not been getting.I'm using this context method to capture my image because i have an overlay on my video,using thumbnail method i cant capture video with overlay but i want to get video's image with overlay.

编辑:
我想要的是获取截图此视频和图纸叠加,如此图片所示

what i want is getting screenshot of both this video and drawing overlay as shown in this image

但是我得到的是一种方法,我只得到视频没有叠加在我的屏幕截图中,方法是缩略图方法,我正在进行缩略图,由MPMoviePlayerController和第二种方法我只得到在ma截图中不覆盖视频,那个方法是上下文方法。我得到rect的上下文。现在我认为解决方案可能是ki结合这两个图像。所以通过给出建议帮助我合并图像对我有用吗?

But what i m getting is by one method i got only video not overlay in my screenshot that method is thumbnail method,i was doing thumbnailing in that which is given by MPMoviePlayerController and by second method i m getting only overlay not an video in ma screenshot,that method is context method.i'm getting context of rect.Now i thought solution for this may be is k i combine both these images.So help me out by giving suggestion is merging images will work for me or not???

请帮忙。谢谢:)

推荐答案

你可以合并两张图片从这个方面来看。请看下面的代码..

U can merge two image from this way.Please have an look from the below code..

- (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;
}

这篇关于如何通过iPhone中的MPMediaPlayerController播放视频截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆