TCMask

Swift

class TCMask : NSObject

Objective-C

@interface TCMask : NSObject

TCMask is the masking result from TCMaskView

  • Initialize a TCMask

    Declaration

    Swift

    public init(data: [UInt8], size: CGSize)

    Objective-C

    - (nonnull instancetype)initWithData:(NSArray * _Nonnull)data size:(CGSize)size OBJC_DESIGNATED_INITIALIZER;
  • Data of masking result

    Declaration

    Swift

    let data: [UInt8]

    Objective-C

    @property (nonatomic, readonly, copy) NSArray * _Nonnull data;
  • Size of mask

    Declaration

    Swift

    let size: CGSize

    Objective-C

    @property (nonatomic, readonly) CGSize size;
  • Create a gray scale UIImage from mask

    Declaration

    Swift

    func grayScaleImage() -> UIImage

    Objective-C

    - (UIImage * _Nonnull)grayScaleImage;

    Return Value

    Gray scale image converted from mask

  • Create a RGBA UIImage from mask

    Declaration

    Swift

    func rgbaImage() -> UIImage

    Objective-C

    - (UIImage * _Nonnull)rgbaImage;

    Return Value

    RGBA image converted from mask, with the alpha info of premultiplied last. If a pixel value of mask is v, the corrosponding pixel value of returned RGBA image is (v, v, v, v)

  • Create a new mask which is the inversion of the original mask

    Declaration

    Swift

    func inverted() -> TCMask

    Objective-C

    - (TCMask * _Nonnull)inverted;
  • Cutout a image using mask

    Declaration

    Swift

    func cutout(image: UIImage, resize: Bool) -> UIImage?

    Objective-C

    - (UIImage * _Nullable)cutoutWithImage:(UIImage * _Nonnull)image resize:(BOOL)resize;

    Parameters

    image

    Image to cutout

    resize

    Specify true to resize the output image to fit the result size

    Return Value

    Nil if resize is set to true and mask only contains 0, otherwise image with cutout

  • Cutout an image using mask

    Declaration

    Swift

    func cutout(image: UIImage, resize: Bool, outputRect: inout CGRect) -> UIImage?

    Objective-C

    - (UIImage * _Nullable)cutoutWithImage:(UIImage * _Nonnull)image resize:(BOOL)resize;

    Parameters

    image

    Image to cutout

    resize

    Specify true to resize the output image to fit the result size

    outputRect

    OUT parameter, which returns The rect of output image in original image. If the result image is nil, outputRect will be (0, 0, 0, 0); If resize is set to false, outputRect will be (0, 0, image.width, image.height)

    Return Value

    Nil if resize is set to true and mask only contains 0, result image with cutout otherwise

  • Create an image blended with mask

    Declaration

    Swift

    func blend(foregroundImage: UIImage, backgroundImage: UIImage) -> UIImage

    Objective-C

    - (UIImage * _Nonnull)blendWithForegroundImage:(UIImage * _Nonnull)foregroundImage backgroundImage:(UIImage * _Nonnull)backgroundImage;

    Parameters

    foregroundImage

    Foregournd image, image size should match mask size

    backgroundImage

    Background image, image size should match mask size

    Return Value

    Blended image