2015-05-11 95 views
0

我需要點擊一個按鈕才能獲得視頻的屏幕截圖。下面是用於該視頻的代碼,但該圖像僅顯示視頻的底部,即播放和隨着時間的推移進展..我用MPMoviePlayerController來播放視頻。屏幕截圖不會顯示視頻中的圖像

CGRect rect = [_moviePlayer.view bounds]; 
UIGraphicsBeginImageContext(rect.size); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
[_moviePlayer.view.layer renderInContext:context]; 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, 100, 100)]; 
[imgView setImage:image]; 
imgView.layer.borderWidth = 2.0; 
[_firstimage addSubview:imgView]; 

NSURL * url = [NSURL URLWithString:@「http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8」];

enter image description here

這是怎麼了shows..How可我得到的視頻圖像?任何人都可以幫助我..

+0

檢查這兩個答案http://stackoverflow.com/questions/13855340/is-there-any-way-to-take -a-screenshot-when-mpmovieplayercontroller-is-playing或http://stackoverflow.com/questions/11258765/mpmovieplayercontroller-taking-screen-shot-but-showing-only-black-screen – Rog

+0

@Rog第二個鏈接幫助。 。謝謝 – Prarthana

回答

0
CGImageRef originalImage = UIGetScreenImage(); 
CGImageRef videoImage = CGImageCreateWithImageInRect(originalImage, CGRectMake(0, 0, 680, 300)); 
UIImage *snapShotImage = [UIImage imageWithCGImage:videoImage]; 
UIImageWriteToSavedPhotosAlbum(snapShotImage, nil, nil, nil); 
CGImageRelease(originalImage); 
CGImageRelease(videoImage); 
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, 250, 200)]; 
[imgView setImage:snapShotImage]; 
imgView.layer.borderWidth = 2.0; 
[_firstimage addSubview:imgView]; 

此代碼的工作...感謝您的幫助...