Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to render AVCaptureVideoPreviewLayer in a graphics context?
    primarykey
    data
    text
    <p>This seems like a simple task, yet it is driving me nuts. <strong>Is it possible to convert a UIView containing AVCaptureVideoPreviewLayer as a sublayer into an image to be saved?</strong> I want to create an augmented reality overlay and have a button save the picture to the camera roll. Holding the power button + home key captures the screenshot to the camera roll, meaning that all of my capture logic is working, AND the task is possible. But I cannot seem to be able to make it work programmatically. </p> <p>I'm capturing a live preview of the camera's image using AVCaptureVideoPreviewLayer . All of my attempts to render the image fail:</p> <pre><code> previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession]; //start the session, etc... //this saves a white screen - (IBAction)saveOverlay:(id)sender { NSLog(@"saveOverlay"); UIGraphicsBeginImageContext(appDelegate.window.bounds.size); UIGraphicsBeginImageContext(scrollView.frame.size); [previewLayer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()]; // [appDelegate.window.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(screenshot, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); } </code></pre> <p>//this renders everything, EXCEPT for the preview layer, which is blank. </p> <pre><code>[appDelegate.window.layer renderInContext:UIGraphicsGetCurrentContext()]; </code></pre> <p>I've read somewhere that this may be due to security issues of the iPhone. Is this true?</p> <p>Just to be clear: <strong>I don't want to save the image for the camera. I want to save the transparent preview layer superimposed over another image, thus creating transparency.</strong> Yet for some reason I cannot make it work. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload