Taking a screenshot of UIView in iOS

I am running iOS 4.3 and trying to take a screenshot of a UIView that plays a movie. The problem is that the screenshot (in the simulator) turns out to be just a black background, and not the image of the movie I was hoping for. My code is below, any ideas what could 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]; } 
+4
source share
1 answer

In the end, I found a solution to this problem. As mentioned above, joerick cannot take a screenshot (using renderInContext) because the movie uses the OpenGL layer to draw its video.

However, there is a way to make a movie thumbnail (shown below for the current playback time):

 UIImage *image = [moviePlayer thumbnailImageAtTime:moviePlayer.currentPlaybackTime timeOption:MPMovieTimeOptionNearestKeyFrame]; 

Hope this helps someone :)

+2
source

Source: https://habr.com/ru/post/1398502/


All Articles