4

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]; } 
2
  • I am not sure, but your problem may be in [self.layer renderInContext:UIGraphicsGetCurrentContext()]; because you taking the screenshot of the self.layer instead of your movieplayer view. Commented Feb 26, 2012 at 23:14
  • 1
    I expect that the movie view is using an OpenGL layer to draw its video, so this won't work. Commented Feb 27, 2012 at 10:24

1 Answer 1

2

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 :)

Sign up to request clarification or add additional context in comments.

1 Comment

so no way to take the actual screenshot? I have very limited knowledge of OpenGL but Apple Doc has some code to take screenshot. I am not able get this code compiled for me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.