Home

Awesome

TinyCrayon SDK for iOS

A smart and easy-to-use image masking and cutout SDK for mobile apps.

platform Compatible CocoaPods Documentation App Store license

TinyCrayon SDK provides tools for adding image cutout and layer mask capabilities to your mobile applications.

Quick Select ToolHair Brush Tool
Quick Select ToolHair Brush Tool

Table of Contents

Overview

TinyCrayon SDK provides tools for adding image cutout and layer mask capabilities to your mobile applications.

Image layer mask is a fundamental technique in image manipulations. It allows you to selectively modify the opacity (transparency) of the layer they belong to. This flexibility to define the opacity of different areas of a layer is the basis for more interesting image manipulation techniques such as selective coloring and luminosity masking.

The current version of TinyCrayon SDK provides the following three tools:

Features

create as many effects as you can think of

Installation

Prerequisites

Steps

  1. Git clone this repo
  2. Download OpenCV2 for iOS pack
  3. Unzip opencv-xxx.zip, move opencv2.framework to TCCore folder
  4. Open your project, drag TinyCrayon.xcodeproj to your workspace, then add TCMask to Frameworks, Libraries, and Embeded Content in your target->General settings

Settings for Objective-C

If your project is using Objective-C, set Always Embed Swift Standard Libraries to be YES in your Build Settings.

Usage

Add a TCMaskView

The TCMaskView class is responsible to create a UIViewController for the user to mask the image. To present a TCMaskView:

Swift

let maskView = TCMaskView(image: image)
maskView.delegate = self
maskView.presentFrom(rootViewController: self, animated: true)

Objective-C

TCMaskView *maskView = [[TCMaskView alloc] initWithImage:image];
maskView.delegate = self;
[maskView presentFromRootViewController:self animated:true];

The delegate of the TCMaskView can be used to be notified when the user cancels or completes the edit. In last case the function tcMaskViewDidComplete(mask:image:) is called.

TCMask class

TCMask is provided by TCMaskViewDelegate functions as the first parameter when the user cancels or completes the edit. For example, when the user completes the edit with TCMaskView:

swift

func tcMaskViewDidComplete(mask: TCMask, image: UIImage) {}

Objective-C

- (void)tcMaskViewDidCompleteWithMask:(TCMask *)mask image:(UIImage *)image {}

TCMask is an encapsulation of image masking result from TCMaskView, it has the following properties:

TCMask also provides some simple and easy to use functions to process layer mask with image. For example, to cutout an object:

Swift

let outputImage = mask.cutout(image: image, resize: false)

Objective-C

UIImage *outputImage = [mask cutoutWithImage:image resize:false];

To try these examples, and find out about more options please take a look at the Examples.

Further reading

License

The MIT license