I am currently making a video collage app. I have one view that contains Avplayerlayer as a sublayer. I need to get a screen shot of the view that contains AvplayerLayer. When I tried to take it it gets the screen shot but for the avplayerlayer(which the video is playing inside) is not in the screenshot, just a black screen. For simulator is perfectly working and showing the layer also but for the real device just a black screen.
I tried all the solutions in StackOverFlow and appleds'developer documentation but nothing worked.
Some solutions that I tried:
swift: How to take screenshot of AVPlayerLayer()
Screenshot for AVPlayer and Video
https://developer.apple.com/documentation/avfoundation/avcapturevideopreviewlayer
As you can see on my code it should work for getting the images from the view but for the avplayerlayer is not working.
- (UIImage *)imageFromView:(UIView *)view
{
UIGraphicsBeginImageContext(view.frame.size);
[view drawViewHierarchyInRect:_videoFrame afterScreenUpdates:false];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
NSString *fileExtension = @"png";
NSData *data;
Boolean *isOutputJPS = false;
if (isOutputJPS) {
data = UIImageJPEGRepresentation(image, 0.5);
fileExtension = @"jpg";
}else{
data = UIImagePNGRepresentation(image);
}
UIImage *rasterizedView = [UIImage imageWithData:data];
UIGraphicsEndImageContext();
return rasterizedView;
}
//in the viewController
UIImage *image = [self imageFromView:recordingView];
I am bit desperate now because there is no any solution for the Avplayerlayer. When I check the images generated in the real device.it just shows me the view but for the simulator it works as I expect.