Reputation: 525
I'm running iOS 4.3 & trying to take a screenshot of a UIView which is playing a movie. The problem is that the screenshot (in the simulator) turns out to be simply a black background & not the movie image i was hoping for. My code is below, any ideas what the matter might be? thanks in advance :)
- (void) takeScreenshot;
{
UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.0);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *movieImage = [[UIImageView alloc] initWithImage:screenshot];
[self addSubview:movieImage];
}
Upvotes: 4
Views: 1289
Reputation: 525
I eventually found a solution to this issue - as joerick mentioned above one can't take a screenshot (using renderInContext) as the movie is using an OpenGL layer to draw its video.
However there is a way to take a thumbnail of a movie (shown below for the current playback time):
UIImage *image = [moviePlayer thumbnailImageAtTime:moviePlayer.currentPlaybackTime timeOption:MPMovieTimeOptionNearestKeyFrame];
Hope this helps someone out :)
Upvotes: 2