4

有人可以幫我嗎?我想通過MPMediaPlayerController播放視頻獲取屏幕截圖。什麼到目前爲止,我已經試過是: -如何在iPhone中通過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

現在發生的事情是我的球員的按鈕越來越在擷取屏幕畫面,但我視頻的圖像沒有越來越多。我使用這種上下文方法來捕捉我的圖像,因爲 我有一個覆蓋在我的視頻,使用縮略圖的方法,我不能捕捉視頻與覆蓋,但我想獲得覆蓋視頻的圖像。

編輯: 我要的是讓這兩個視頻的截圖和繪圖疊加,如圖這一形象 Overlay on Video

什麼,但什麼IM越來越是一個方法我只有視頻不是我的截圖覆蓋該方法是縮略圖方法,我正在縮略圖,這是由MPMoviePlayerController給出的,並通過第二種方法即時獲取只覆蓋不是一個視頻在ma屏幕截圖,該方法是上下文method.i'm獲取rect的上下文。現在我認爲解決方案因爲這可能是ki結合這兩個圖像。所以幫助我通過提供建議合併圖像將適用於​​我嗎?

請help.Thanks :)

+0

你用openGL? – zahreelay

+0

否一點也不,我使用MediaPlayer框架來播放沒有別的東西我用過的視頻:) –

回答

1

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

這可能有助於

- (UIImage *)thumbnailImageAtTime:(NSTimeInterval)playbackTime timeOption:(MPMovieTimeOption)option 

在給定時間獲取thumbnailImage和規模的形象。

+0

我已經做了它,但它沒用,因爲我有一個覆蓋在我的視頻,這個縮略圖,我們只能得到視頻的圖像不是疊加層的圖像。 –

2

你只需要調用一個方法你mpmovieplayer對象:

- (UIImage *)thumbnailImageAtTime:(NSTimeInterval)playbackTime timeOption:(MPMovieTimeOption)option

此方法將返回一個UIImage對象。你所要做的僅僅是:

UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame]; 

更多細節看MPMoviePlayerController

希望這有助於

編輯:在你的方法,你可以先隱藏玩家的控制,比捕獲圖像之後再次顯示控件。您可以使用MPMoviePlayerController的controlStyle屬性來實現此目的。

不知道這是你在找什麼,但這是我的理解。如果你正在尋找不同的東西讓我知道。

+0

我使用這種上下文方法來捕捉我的圖像,因爲我有一個覆蓋在我的視頻上,使用縮略圖方法,我無法捕捉覆蓋的視頻,但我想要覆蓋視頻的圖像。 –

+0

我更新了我的答案。讓我知道如果這仍然不是你正在尋找 –

+0

嘿傢伙我想要做的是設置一個覆蓋視頻和捕捉image.when我捕捉圖像視頻播放器的按鈕顯示在圖像中,但視頻的圖像不顯示爲如上圖所示。 –

相關問題