- Notifications
You must be signed in to change notification settings - Fork157
A smart and easy-to-use image masking and cutout SDK for mobile apps.
License
TinyCrayon/TinyCrayon-iOS-SDK
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A smart and easy-to-use image masking and cutout SDK for mobile apps.
TinyCrayon SDK provides tools for adding image cutout and layer mask capabilities to your mobile applications.
![]() | ![]() |
---|---|
Quick Select Tool | Hair Brush Tool |
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:
- Quick Select: Smart and easy to use, users just need to select part of the object and the edge detection algorithm will find the boundary.
- Hair Brush: Smooth and natual looking, paint on the hair/fur of an object and the algorithm will select the hair/fur for you in high quality.
- Regular Brush: A regular brush tool with the capability to adjust its size, hardness and opacity.
- Free: TinyCrayon SDK is provided under MIT license, you can use it in your commercial applications for free!
- iPad support: TinyCrayon SDK uses auto layout for its views and adapts to each screen size - iPhone or iPad.
- Highly customizable: Style the UI, view modes and localized languages as you wish.
- Swift: Keeping up with time, we chose Swift as the main development language of the TinyCrayon SDK, leading to leaner easier code.
- Objective-C support: All of our public API is Objective-C compatible.
- Xcode 9.0 or later.
- A physical iOS device.
- Git clone this repo
- DownloadOpenCV2 for iOS pack
- Unzip opencv-xxx.zip, moveopencv2.framework to TCCore folder
- Open your project, dragTinyCrayon.xcodeproj to your workspace, then addTCMask toFrameworks, Libraries, and Embeded Content in your target->General settings
If your project is using Objective-C, setAlways Embed Swift Standard Libraries
to be YES in your Build Settings.
TheTCMaskView
class is responsible to create aUIViewController
for the user to mask the image.To present aTCMaskView
:
Swift
let maskView = TCMaskView(image: image)maskView.delegate = selfmaskView.presentFrom(rootViewController: self, animated: true)
Objective-C
TCMaskView *maskView = [[TCMaskView alloc] initWithImage:image];maskView.delegate = self;[maskView presentFromRootViewController:self animated:true];
The delegate of theTCMaskView
can be used to be notified when the user cancels or completes the edit. In last case the functiontcMaskViewDidComplete(mask:image:)
is called.
TCMask
is provided byTCMaskViewDelegate
functions as the first parameter when the user cancels or completes the edit. For example, when the user completes the edit withTCMaskView
:
swift
func tcMaskViewDidComplete(mask: TCMask, image: UIImage) {}
Objective-C
- (void)tcMaskViewDidCompleteWithMask:(TCMask *)mask image:(UIImage *)image {}
TCMask
is an encapsulation of image masking result fromTCMaskView
, it has the following properties:
- data: An array of 8-bits unsigned char, its length is equal to the number of pixels of the image in
TCMaskView
. Each element in data represents the mask value. - size: The size of mask, which is equal to the size of the image in
TCMaskView
.
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 theExamples.
- Check out TinyCrayonguides andAPI reference for more details.
The MIT license
About
A smart and easy-to-use image masking and cutout SDK for mobile apps.