iOS 10: Capturing Photo Thumbnails | Ray Wenderlich

AVCapturePhotoOutput has the ability to create preview images really quickly. Discover how to use this new functionality.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4999-ios-10-capturing-photo-thumbnails

Would this be the same process as acquiring a High quality full sized image preview. Like snapchat with the ability to take a photo and immediately see the captured photo?

Hi @elliott_19

If you want to grab the full-size image, then you should just be able to use the full quality photo. Or maybe ask for a high-resolution thumbnail for live processing?

I think you’ll have to experiment with performance on different devices - and see whether you can get the performance you need.

sam

Sam this might be a little off topic but I cant figure out how CameraPreviewView code works. We are returning the view’s layer as an AVCaptureVideoPreviewLayer but the view’s layer is just a CALayer. At what point does the CALayer become AVCaptureVideoPreviewLayer?

Hi @sigod,

There is a class property on UIView called layerClass. You can override this in a subclass of UIView and use it to specify what kinda of CALayer subclass you’d like instances of this view to be backed by. In the code for CameraPreviewView the following code provides the layer subclass:

override static var layerClass: AnyClass {
  return AVCaptureVideoPreviewLayer.self
}

That means that when you ask for the layer property of that view, you’ll be given an instance of AVCaptureVideoPreviewLayer, however, the property still has the type CALayer (since it is inherited). Therefore, we add a new property to CameraPreviewView to return the layer of the correct type:

var cameraPreviewLayer: AVCaptureVideoPreviewLayer {
  return layer as! AVCaptureVideoPreviewLayer
}

Hope that helps!

sam

1 Like