WKCImageEditorTool
图片编辑,滤镜、亮度调节、旋转、画笔、贴图、马赛克、文本、裁剪.
pod 'WKCImageEditorTool'
#import <WKCImageEditorTool/WKCImageEditorTool.h>
主体 WKCImageEditorTool 有三个代理回调.
- 回调编辑中的图片 - 展示效果用(滤镜、旋转、亮度模式有效).
- (void)imageEditorTool:(WKCImageEditorTool *)tool
editingImage:(UIImage *)editing;
- 回调编辑确认的图片
- (void)imageEditorTool:(WKCImageEditorTool *)tool
editedImage:(UIImage *)edited;
- 彻底取消,回调原始图
- (void)imageEditorTool:(WKCImageEditorTool *)tool
cancelImage:(UIImage *)cancel;
具体的各个工具属性设置,去设置各个tool属性.(最后的位置附各工具属性和方法列表).
/**滤镜工具*/
@property (nonatomic, strong) WKCFilterTool * filterTool;
/**旋转工具*/
@property (nonatomic, strong) WKCRotationTool * rotationTool;
/**画笔工具*/
@property (nonatomic, strong) WKCDrawTool * drawTool;
/**贴图工具*/
@property (nonatomic, strong) WKCStickersTool * stickerTool;
/**马赛克工具*/
@property (nonatomic, strong) WKCMosaicTool * mosaicTool;
/**文本工具*/
@property (nonatomic, strong) WKCTextTool * textTool;
/**亮度工具*/
@property (nonatomic, strong) WKCBrightTool * brightTool;
/**裁剪工具*/
@property (nonatomic, strong) WKCClipTool * clipTool;
滤镜
- 源图与滤镜后的图都会在子线程强制解析,解析后缓存,再在主线程回调.再次加载会加载缓存图片.
- 使用如下:
- (WKCImageEditorTool *)editorTool {
if (!_editorTool) {
_editorTool = [[WKCImageEditorTool alloc] initWithFrame:self.imageView.bounds sourceImage:self.imageView.image];
_editorTool.editorType = WKCImageEditorToolTypeFilter;
_editorTool.delegate = self;
}
return _editorTool;
}
添加到父视图(需要展示的图片imageView上).
[self.imageView addSubview:self.editorTool];
设置类型为滤镜,在触发事件内,设置类型,开启使用即可
self.editorTool.filterTool.filterType = WKCFilterTypeInstant;
[self.editorTool fire];
使用完成后,工具会自动关闭.某些模式下需要手动,调用- (void)confirm;
去回调结果并关闭(例如画笔、图贴等,需要编辑完成再确认操作的).
效果图:
带一些特效的:
旋转
- 使用(用法都一样).
- (WKCImageEditorTool *)editorTool {
if (!_editorTool) {
_editorTool = [[WKCImageEditorTool alloc] initWithFrame:self.imageView.bounds sourceImage:self.imageView.image];
_editorTool.editorType = WKCImageEditorToolTypeRotation;
_editorTool.delegate = self;
}
return _editorTool;
}
- 事件触发.
[self.editorTool fire];
self.editorTool.rotationTool.rotationType = WKCImageRotationTypeOrientationLeft;
- 效果图
画笔
- 使用
- (WKCImageEditorTool *)editorTool {
if (!_editorTool) {
_editorTool = [[WKCImageEditorTool alloc] initWithFrame:self.imageView.bounds sourceImage:self.imageView.image];
_editorTool.editorType = WKCImageEditorToolTypeDraw;
_editorTool.delegate = self;
}
return _editorTool;
}
- 开启
[self.editorTool fire];
- 确认
[self.editorTool confirm];
- 效果图
贴图
贴图与上边有些区别.贴图初始时需要设置贴图和删除键.其有另外的初始方法.(但仍包含上述方法的初始,各初始化是递进关系,并不是单一关系).
- 初始化
- (WKCImageEditorTool *)editorTool {
if (!_editorTool) {
_editorTool = [[WKCImageEditorTool alloc] initWithFrame:self.imageView.bounds sourceImage:self.imageView.image stickerImage:[UIImage imageNamed:@"toolBar_stickes_1"] deleteImage:[UIImage imageNamed:@"toolBar_stickes_delete"]];
_editorTool.editorType = WKCImageEditorToolTypeSticker;
_editorTool.delegate = self;
}
return _editorTool;
}
-
橡皮擦 调用
[self.editorTool.drawTool eraser];
开启橡皮擦模式. 其他方法相同,之后不重复写了. -
效果图
马赛克
- 使用
- (WKCImageEditorTool *)editorTool {
if (!_editorTool) {
_editorTool = [[WKCImageEditorTool alloc] initWithFrame:self.imageView.bounds sourceImage:self.imageView.image];
_editorTool.editorType = WKCImageEditorToolTypeMosaic;
_editorTool.delegate = self;
}
return _editorTool;
}
- 效果图
文本
文本也要个别的初始化方法.
- 使用
- (WKCImageEditorTool *)editorTool {
if (!_editorTool) {
_editorTool = [[WKCImageEditorTool alloc] initWithFrame:self.imageView.bounds sourceImage:self.imageView.image textDelete:[UIImage imageNamed:@"toolBar_stickes_delete"]];
_editorTool.editorType = WKCImageEditorToolTypeText;
_editorTool.delegate = self;
}
return _editorTool;
}
- 效果图