iOS Developer Library

Developer

AV Foundation Framework Reference AVCaptureStillImageOutput Class Reference

Options
Deployment Target:

On This Page
Language:

AVCaptureStillImageOutput

AVCaptureStillImageOutput is a concrete sub class of AVCaptureOutput that you use to capture a high-quality still image with accompanying metadata.

In iOS 8.0 and later support for still image bracketed capture has been added. A "still image bracket" is a batch of images taken as quickly as possible in succession, optionally with different settings from picture to picture.

In a bracketed capture, AVCaptureDevice instance’s flashMode property is ignored (flash is forced off), as is the automaticallyEnablesStillImageStabilizationWhenAvailable property (stabilization is forced off).

  • Initiates a still image capture and returns immediately.

    Declaration

    Swift

    func captureStillImageAsynchronouslyFromConnection(_ connection: AVCaptureConnection!, completionHandler handler: ((CMSampleBuffer!, NSError!) -> Void)!)

    Objective-C

    - (void)captureStillImageAsynchronouslyFromConnection:(AVCaptureConnection *)connection completionHandler:(void (^)(CMSampleBufferRef imageDataSampleBuffer, NSError *error))handler

    Parameters

    connection

    The connection from which to capture the image.

    handler

    A block to invoke after the image has been captured. The block parameters are as follows:

    imageDataSampleBuffer

    The data that was captured.

    The buffer attachments may contain metadata appropriate to the image data format. For example, a buffer containing JPEG data may carry a kCGImagePropertyExifDictionary as an attachment. See ImageIO/CGImageProperties.h for a list of keys and value types.

    error

    If the request could not be completed, an NSError object that describes the problem; otherwise nil.

    Discussion

    This method returns immediately after it is invoked, later calling the provided completion handler block when image data is ready. If the request could not be completed, the error parameter will contain an NSError object describing the failure.

    You should not assume that the completion handler will be called on a specific thread.

    Availability

    Available in iOS 4.0 and later.

  • Indicates whether a still image is being captured. (read-only)

    Declaration

    Swift

    var capturingStillImage: Bool { get }

    Objective-C

    @property(readonly, getter=isCapturingStillImage) BOOL capturingStillImage

    Discussion

    The value of this property is YEStrue when a still image is being captured, and NOfalse when no still image capture is underway.

    This property supports key-value observing.

    Availability

    Available in iOS 5.0 and later.

  • Returns an NSData representation of a still image data and metadata attachments in a JPEG sample buffer.

    Declaration

    Swift

    class func jpegStillImageNSDataRepresentation(_ jpegSampleBuffer: CMSampleBuffer!) -> NSData!

    Objective-C

    + (NSData *)jpegStillImageNSDataRepresentation:(CMSampleBufferRef)jpegSampleBuffer

    Parameters

    jpegSampleBuffer

    The sample buffer carrying JPEG image data, optionally with Exif metadata sample buffer attachments.

    This method throws an NSInvalidArgumentException if jpegSampleBuffer is NULL or not in the JPEG format.

    Return Value

    An NSData representation of jpegSampleBuffer.

    Discussion

    This method merges the image data and Exif metadata sample buffer attachments without re-compressing the image.

    The returned NSData object is suitable for writing to disk.

    Availability

    Available in iOS 4.0 and later.