UIImage(CVPixelBuffer)

@interface UIImage (CVPixelBuffer)

TensorIO extensions to UIImage, specifically for converting images to and from instances of CVPixelBufferRef.

  • Instantiates an image from a pixel buffer, assuming a scaling factor of 1.0 and an orientation of UIImageOrientationUp.

    Declaration

    Objective-C

    - (nullable instancetype)initWithPixelBuffer:
        (nonnull CVPixelBufferRef)pixelBuffer;

    Swift

    init?(pixelBuffer: CVPixelBuffer)

    Parameters

    pixelBuffer

    The source pixel buffer.

    Return Value

    UIImage The resulting image.

  • Instantiates an image from a pixel buffer.

    Declaration

    Objective-C

    - (nullable instancetype)initWithPixelBuffer:
                                 (nonnull CVPixelBufferRef)pixelBuffer
                                           scale:(CGFloat)scale
                                     orientation:(UIImageOrientation)orientation;

    Swift

    init?(pixelBuffer: CVPixelBuffer, scale: CGFloat, orientation: UIImage.Orientation)

    Parameters

    pixelBuffer

    The source pixel buffer.

    scale

    The image scale.

    orientation

    The resulting image’s orientation.

    Return Value

    UIImage The resulting image.

  • Creates a pixel buffer from the receiver via Core Graphics.

    The pixel buffer will have the following format:

    • Pixel Format: kCVPixelFormatType_32ARGB.

    • Alpha: kCGImageAlphaNoneSkipFirst.

    • Color Space: Device RGB.

    Declaration

    Objective-C

    - (nullable CVPixelBufferRef)pixelBuffer;

    Swift

    func pixelBuffer() -> Unmanaged<CVPixelBuffer>?

    Return Value

    CVPixelBufferRef An autoreleased pixel buffer.

  • Creates a pixel buffer from the receiver via Core Graphics.

    Declaration

    Objective-C

    - (nullable CVPixelBufferRef)pixelBuffer:(OSType)format
                                  colorSpace:(nonnull CGColorSpaceRef)colorSpace
                                   alphaInfo:(CGImageAlphaInfo)alphaInfo;

    Swift

    func pixelBuffer(_ format: OSType, colorSpace: CGColorSpace, alphaInfo: CGImageAlphaInfo) -> Unmanaged<CVPixelBuffer>?

    Parameters

    format

    The pixel format of the resulting pixel buffer.

    colorSpace

    The color space of the resulting pixel buffer.

    alphaInfo

    Alpha channel info for the resulting pixel buffer.

    Return Value

    An autoreleased CVPixelBufferRef.