AVCaptureVideoPreviewLayer: taking a snapshot

前端 未结 4 1773
不知归路
不知归路 2020-12-14 03:53

I\'m trying to emulate the animation seen in the default camera app, where a snapshot of the cameras viewfinder is animated into the corner of the apps display.

The

4条回答
  •  粉色の甜心
    2020-12-14 04:15

    Starting in iOS 7, you can use UIView::snapshotViewAfterScreenUpdates to snapshot the UIView wrapping your AVCaptureVideoPreviewLayer. This is not the same as UIGetScreenImage, which will get your app rejected.

    UIView *snapshot = [self.containerView snapshotViewAfterScreenUpdates:YES];
    

    Recall the old-school way of turning a view into an image. For some reason it worked on everything except for camera previews:

    UIGraphicsBeginImageContextWithOptions(self.containerView.bounds.size, NO, [UIScreen mainScreen].scale);
    [self.containerView drawViewHierarchyInRect:self.containerView.bounds afterScreenUpdates:YES];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

提交回复
热议问题