Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First of all the obvious stuff that doesn't relate directly to your question: <code>AVCaptureVideoPreviewLayer</code> is the cheapest way to pipe video from either of the cameras into an independent view if that's where the data is coming from and you've no immediate plans to modify it. You don't have to do any pushing yourself, the preview layer is directly connected to the <code>AVCaptureSession</code> and updates itself.</p> <p>I have to admit to lacking confidence about the central question. There's a semantic difference between a <code>CIImage</code> and the other two types of image — a <code>CIImage</code> is a recipe for an image and is not necessarily backed by pixels. It can be something like "take the pixels from here, transform like this, apply this filter, transform like this, merge with this other image, apply this filter". The system doesn't know what a <code>CIImage</code> looks like until you chose to render it. It also doesn't inherently know the appropriate bounds in which to rasterise it.</p> <p><code>UIImage</code> purports merely to wrap a <code>CIImage</code>. It doesn't convert it to pixels. Presumably <code>UIImageView</code> should achieve that, but if so then I can't seem to find where you'd supply the appropriate output rectangle.</p> <p>I've had success just dodging around the issue with:</p> <pre><code>CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixelBuffer]; CIContext *temporaryContext = [CIContext contextWithOptions:nil]; CGImageRef videoImage = [temporaryContext createCGImage:ciImage fromRect:CGRectMake(0, 0, CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer))]; UIImage *uiImage = [UIImage imageWithCGImage:videoImage]; CGImageRelease(videoImage); </code></pre> <p>With gives an obvious opportunity to specify the output rectangle. I'm sure there's a route through without using a <code>CGImage</code> as an intermediary so please don't assume this solution is best practice.</p>
 

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