steamx / CLImageEditor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CLImageEditor

CLImageEditor provides basic image editing features to iPhone apps. This ViewController is simple to use, and is also possible to incorporate as part of the UIImagePickerController easily.

sample

Installing

The easiest way to use CLImageEditor is to copy all the files in the CLImageEditor group (or directory) into your app. Alternatively, you should be able to setup a git submodule and reference the files in your Xcode project.

Add the following frameworks to your project: CoreGraphics, CoreImage, Accelerate

Or CocoaPods

pod 'CLImageEditor'

Usage

Getting started with CLImageEditor is dead simple. Just initialize it with an UIimage and set a delegate. Then you can use it as a usual ViewController.

#import "CLImageEditor.h"

@interface ViewController()
<CLImageEditorDelegate>
@end

- (void)presentImageEditorWithImage:(UIImage*)image
{
    CLImageEditor *editor = [[CLImageEditor alloc] initWithImage:image];
    editor.delegate = self;
	
    [self presentViewController:editor animated:YES completion:nil];
}

When used with UIImagePickerController, CLImageEditor can be made to function as a part of the picker by to call the picker's pushViewController:animated:.

#pragma mark- UIImageController delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    
    CLImageEditor *editor = [[CLImageEditor alloc] initWithImage:image];
    editor.delegate = self;
    
    [picker pushViewController:editor animated:YES];
}

After a image has been edited, the editor will call delegate's imageEditor:didFinishEdittingWithImage: method. The delegate's method is required to receive edited image.

#pragma mark- CLImageEditor delegate

- (void)imageEditor:(CLImageEditor *)editor didFinishEdittingWithImage:(UIImage *)image
{
    _imageView.image = image;
    [editor dismissViewControllerAnimated:YES completion:nil];
}

Additionally, the optional delegate's imageEditorDidCancel: method is provided for when you want to catch the cancel callback.

For more detail, please see CLImageEditorDemo.

Customizing

Icon images are included in CLImageEditor.bundle. You can change the appearance by rewriting the icon images.

Other features for theme settings not yet implemented.

Menu customization

Image tools can customize using CLImageToolInfo. CLImageEditor's toolInfo property has functions to access each tool's info. For example, subToolInfoWithToolName:recursive: method is used to get the tool info of a particular name.

CLImageEditor *editor = [[CLImageEditor alloc] initWithImage:_imageView.image];
editor.delegate = self;

CLImageToolInfo *tool = [editor.toolInfo subToolInfoWithToolName:@"CLToneCurveTool" recursive:NO];

After getting a tool info, by changing its properties, you can customize the image tool on menu view.

CLImageToolInfo *tool = [editor.toolInfo subToolInfoWithToolName:@"CLToneCurveTool" recursive:NO];
tool.title = @"TestTitle";
tool.available = NO;     // if available is set to NO, it is removed from the menu view.
tool.dockedNumber = -1;  // Bring to top
//tool.iconImagePath = @"test.png";
  • dockedNumber determine the menu item order. Note that it is simply used as a key for sorting.

The list of tool names can be confirmed with the following code.

NSLog(@"%@", editor.toolInfo);
NSLog(@"%@", editor.toolInfo.toolTreeDescription);

License

CLImageEditor is released under the MIT License, see LICENSE.

About

License:MIT License