RRImage

Objective-C

@interface RRImage : NSObject

Swift

class RRImage : NSObject

An Image class that provides interoperability functions to work with common UIKit image representations.

  • Initializes the image with an UIImage (a copy is made). Converting large images may be a good idea to do asynchronous to the app’s main thread for preventing unnecessary lag of the main event loop.

    Declaration

    Objective-C

    - (instancetype _Nonnull)initWithImage:(UIImage *_Nonnull)image;

    Swift

    init(image: UIImage)

    Parameters

    image

    Image used for initialization.

    Return Value

    An instance of RRImage.

  • Initializes the image from an NSData object. The content is decoded and copied. Loading large images may be a good idea to do asynchronous to the app’s main thread for preventing unnecessary lag of the main event loop.

    Declaration

    Objective-C

    - (instancetype _Nullable)initWithData:(NSData *_Nonnull)imageData;

    Swift

    init?(data imageData: Data)

    Parameters

    imageData

    Binary representation of an image (JPEG, PNG)

    Return Value

    - returns: An instance of RRImage on success, nil otherwise.

  • Undocumented

    Declaration

    Objective-C

    -(instancetype _Nonnull) initWithRawData:(void* _Nonnull) data andRows:(unsigned) rows andCols:(unsigned) cols andFormat:(RRImageFormat) format andStride:(unsigned) stride;

    Swift

    init(rawData data: UnsafeMutableRawPointer, andRows rows: UInt32, andCols cols: UInt32, andFormat format: RRImageFormat, andStride stride: UInt32)
  • Enforces that the format of an image has a specific type. Nothing happens If the image already has the provided type. Otherwise, the image is converted to the respective type. Channels are dropped or filled with default values.

    Declaration

    Objective-C

    - (BOOL)enforceFormat:(RRImageFormat)imageFormat
         didFailWithError:(NSError *_Nullable *_Nullable)error;

    Swift

    func enforceFormat(_ imageFormat: RRImageFormat) throws

    Parameters

    imageFormat

    One of RRImageFormatRGB, RRImageFormatRGBA or RRImageFormatGray

    error

    An optional pointer to an NSError pointer. When this method fails, it will set an NSError instance to this pointer if provided.

    Return Value

    YES if successful, NO otherwise.

  • Returns the formate of the image

    Declaration

    Objective-C

    - (RRImageFormat)imageFormat;

    Swift

    func imageFormat() -> RRImageFormat

    Return Value

    One of RRImageFormatRGB, RRImageFormatRGBA, RRImageFormatGray or RRImageFormatInvalid

  • Converts the RRImage to an UIImage. Converting large images may be a good idea to do asynchronous to the app’s main thread for preventing unnecessary lag of the main event loop.

    Declaration

    Objective-C

    - (UIImage *_Nonnull)convertToUIImage;

    Swift

    func convertToUIImage() -> UIImage

    Return Value

    A copy of the RRImage as UIImage

  • Creates an actual cloned copy of the image

    Declaration

    Objective-C

    - (RRImage *_Nonnull)clone;

    Swift

    func clone() -> RRImage

    Return Value

    A cloned copy of the image

  • Creates a separate image jus including the alpha channel of the image the method was invoked on

    Declaration

    Objective-C

    - (RRImage *_Nullable)splitAlphaWithError:(NSError *_Nullable *_Nullable)error;

    Swift

    func splitAlpha() throws -> RRImage

    Parameters

    error

    An optional pointer to an NSError pointer. When this method fails, it will set an NSError instance to this pointer if provided.

    Return Value

    The alpha channel of the image. This method returns nil if an error occurs.