UIImage(SBSDK)

@interface UIImage (SBSDK)

@category UIImage(SBSDK) An UIImage class extension to perform basic image processing operations. Direct usage is not recommended for large images. Instead use SBSDKImageProcessor methods to employ queues and proper memory management.

  • Creates a UIImage instance from a pixel buffer.

    Declaration

    Objective-C

    - (nullable id)sbsdk_initFromPixelBuffer:(nonnull CVPixelBufferRef)sampleBuffer;

    Swift

    func sbsdk_init(from sampleBuffer: CVPixelBuffer) -> Any?
  • Creates a UIImage instance from a sample buffer.

    Declaration

    Objective-C

    - (nullable id)sbsdk_initFromSampleBuffer:
        (nonnull CMSampleBufferRef)sampleBuffer;

    Swift

    func sbsdk_init(from sampleBuffer: CMSampleBuffer) -> Any?
  • Converts a CVPixelBufferRef to an UIImage.

    Declaration

    Objective-C

    + (nullable UIImage *)sbsdk_imageFromPixelBuffer:
        (nonnull CVPixelBufferRef)pixelBuffer;

    Swift

    class func sbsdk_image(from pixelBuffer: CVPixelBuffer) -> UIImage?

    Parameters

    pixelBuffer

    The pixel buffer to convert.

    Return Value

    An UIImage.

  • Converts a CMSampleBuffer to an UIImage.

    Declaration

    Objective-C

    + (nullable UIImage *)sbsdk_imageFromSampleBuffer:
        (nonnull CMSampleBufferRef)sampleBuffer;

    Swift

    class func sbsdk_image(from sampleBuffer: CMSampleBuffer) -> UIImage?

    Parameters

    sampleBuffer

    The sample buffer to convert.

    Return Value

    An UIImage.

  • Converts a CVPixelBufferRef to an UIImage.

    Declaration

    Objective-C

    + (nullable UIImage *)
        sbsdk_imageFromPixelBuffer:(nonnull CVPixelBufferRef)pixelBuffer
                       orientation:(AVCaptureVideoOrientation)orientation;

    Swift

    class func sbsdk_image(from pixelBuffer: CVPixelBuffer, orientation: AVCaptureVideoOrientation) -> UIImage?

    Parameters

    pixelBuffer

    The pixel buffer to convert.

    orientation

    The AVFoundation video orientation.

    Return Value

    An UIImage.

  • Converts a CMSampleBuffer to an UIImage.

    Declaration

    Objective-C

    + (nullable UIImage *)
        sbsdk_imageFromSampleBuffer:(nonnull CMSampleBufferRef)sampleBuffer
                        orientation:(AVCaptureVideoOrientation)orientation;

    Swift

    class func sbsdk_image(from sampleBuffer: CMSampleBuffer, orientation: AVCaptureVideoOrientation) -> UIImage?

    Parameters

    sampleBuffer

    The sample buffer to convert.

    orientation

    The AVFoundation video orientation.

    Return Value

    An UIImage.

  • Creates an UIImage of a given size and color.

    Declaration

    Objective-C

    + (nullable UIImage *)sbsdk_imageWithColor:(nonnull UIColor *)color
                                       andSize:(CGSize)size;

    Swift

    class func sbsdk_image(with color: UIColor, andSize size: CGSize) -> UIImage?

    Parameters

    color

    The color to fill the image with.

    size

    The size of the image.

    Return Value

    The resulting image.

  • Applies clockwise 90 degree rotations to the receiver.

    Declaration

    Objective-C

    - (nullable UIImage *)sbsdk_imageRotatedClockwise:(NSInteger)times;

    Swift

    func sbsdk_imageRotatedClockwise(_ times: Int) -> UIImage?

    Parameters

    times

    Number of 90 degree rotations to apply. Can be negative. Uses modulo arithmetics.

    Return Value

    The rotated UIImage.

  • Applies counter-clockwise 90 degree rotations to the receiver.

    Declaration

    Objective-C

    - (nullable UIImage *)sbsdk_imageRotatedCounterClockwise:(NSInteger)times;

    Swift

    func sbsdk_imageRotatedCounterClockwise(_ times: Int) -> UIImage?

    Parameters

    times

    Number of 90 degree rotations to apply. Can be negative. Uses modulo arithmetics.

    Return Value

    The rotated UIImage.

  • Rotates the receiver for the given angle.

    Declaration

    Objective-C

    - (nullable UIImage *)sbsdk_imageRotatedByDegrees:(CGFloat)degrees;

    Swift

    func sbsdk_imageRotated(byDegrees degrees: CGFloat) -> UIImage?

    Return Value

    The rotated image.

  • Rotates the receiver and corrects the orientation flag to UIImageOrientationUp.

    Declaration

    Objective-C

    - (nullable UIImage *)sbsdk_imageWithNormalizedOrientation;

    Swift

    func sbsdk_imageWithNormalizedOrientation() -> UIImage?

    Return Value

    The orientation fixed image.

  • Scales the receiver to the given size.

    Declaration

    Objective-C

    - (nullable UIImage *)sbsdk_imageScaledToSize:(CGSize)size;

    Swift

    func sbsdk_imageScaled(to size: CGSize) -> UIImage?

    Return Value

    The rescaled image.

  • Resets the orientation flag to UIImageOrientationUp without rotating the image data.

    Declaration

    Objective-C

    - (nullable UIImage *)sbsdk_imageWithFixedOrientation;

    Swift

    func sbsdk_imageWithFixedOrientation() -> UIImage?

    Return Value

    Image with modified orientation metadata.

  • Strips the alpha channel from an image.

    Declaration

    Objective-C

    - (nullable UIImage *)sbsdk_imageWithStrippedAlpha;

    Swift

    func sbsdk_imageWithStrippedAlpha() -> UIImage?

    Return Value

    The image without alpha channel.

  • Inverts the colors of the receiver.

    Declaration

    Objective-C

    - (nullable UIImage *)sbsdk_invertedImage;

    Swift

    func sbsdk_inverted() -> UIImage?

    Return Value

    The inverted image.

  • Scales down the image to fit into the given size. Does no upscaling. Does nothing, if width or height equal to zero.

    Declaration

    Objective-C

    - (nullable UIImage *)sbsdk_limitedToSize:(CGSize)imageSize;

    Swift

    func sbsdk_limited(to imageSize: CGSize) -> UIImage?
  • Returns a center crop of the receiver with the given aspect ratio.

    Declaration

    Objective-C

    - (nullable UIImage *)sbsdk_imageByCenterCroppingToAspectRatio:
        (nonnull SBSDKAspectRatio *)ratio;

    Swift

    func sbsdk_imageByCenterCropping(to ratio: SBSDKAspectRatio) -> UIImage?

    Parameters

    ratio

    The aspect ratio of the requested crop.

    Return Value

    The cropped image.

  • Checks, if the receiver is monochromatic (grayscale).

    Declaration

    Objective-C

    - (BOOL)sbsdk_isMonochrome;

    Swift

    func sbsdk_isMonochrome() -> Bool

    Return Value

    YES, if the image is monochromatic, NO otherwise.

  • Converts the receiver to a monochromatic image with less memory usage.

    Declaration

    Objective-C

    - (nullable UIImage *)sbsdk_grayscaledImage;

    Swift

    func sbsdk_grayscaled() -> UIImage?

    Return Value

    The monochromatic image or nil, if the conversion failed.

  • Resets the orientation flag to UIImageOrientationUp without rotating the image data.

    Declaration

    Objective-C

    + (nullable NSData *)sbsdk_imageDataWithFixedOrientation:
        (nullable NSData *)imageData;

    Swift

    class func sbsdk_imageData(withFixedOrientation imageData: Data?) -> Data?

    Return Value

    A new NSData instance containing jpeg image data with corrected metadata.

  • Since the camera sensor is, orientationwise, fixed to the device, a captured images orientation depends on the orientation of the device. This function calculates the number of counterclockwise rotations needed for a captured image to rotate it to the upside-down orientation.

    Declaration

    Objective-C

    + (NSInteger)proposedCounterClockwiseRotationsForOrientation:
        (UIDeviceOrientation)deviceOrientation;

    Swift

    class func proposedCounterClockwiseRotations(for deviceOrientation: UIDeviceOrientation) -> Int

    Parameters

    deviceOrientation

    The orientation of the device when the image was captured.

    Return Value

    The number of counterclockwise rotations needed to ‘unrotate’ the image.