我需要点击一个按钮获取视频的屏幕截图。下面是用于此的代码,但图片仅显示视频的底部部分即播放和进度随着时间的推移..我使用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”];
这就是它如何显示......我如何获得视频图像?任何人都可以帮助我..
答案 0 :(得分:0)
答案 1 :(得分: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];
此代码有效...感谢您的帮助...