美文网首页
iOS 图片编辑

iOS 图片编辑

作者: 师傅我坚持不住了 | 来源:发表于2018-06-26 00:29 被阅读36次

WKCImageEditorTool

图片编辑工具,如滤镜、亮度调节、旋转、画笔、贴图、马赛克、文本、裁剪.

主体使用:

pod 'WKCImageEditorTool'

#import <WKCImageEditorTool/WKCImageEditorTool.h>

主体 WKCImageEditorTool 有三个代理回调.

  1. 回调编辑中的图片 - 展示效果用(滤镜、旋转、亮度模式有效).
- (void)imageEditorTool:(WKCImageEditorTool *)tool
editingImage:(UIImage *)editing;
  1. 回调编辑确认的图片
- (void)imageEditorTool:(WKCImageEditorTool *)tool
editedImage:(UIImage *)edited;
  1. 彻底取消,回调原始图
- (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;

滤镜

源图与滤镜后的图都会在子线程强制解析,提升imageView的显示效率,解析后缓存,再在主线程回调.再次加载会加载缓存图片.

  1. 使用.
- (WKCImageEditorTool *)editorTool {
if (!_editorTool) {
_editorTool = [[WKCImageEditorTool alloc] initWithFrame:self.imageView.bounds sourceImage:self.imageView.image];
_editorTool.editorType = WKCImageEditorToolTypeFilter;
_editorTool.delegate = self;
}
return _editorTool;
}
/**添加到父视图*/
[self.imageView addSubview:self.editorTool];
/**设置类型为滤镜,在触发事件内,设置类型,开启使用*/
self.editorTool.filterTool.filterType = WKCFilterTypeInstant;
[self.editorTool fire];

使用完成后,工具会自动关闭.某些模式下需要手动,调用- (void)confirm;去回调结果并关闭(例如画笔、图贴等,需要编辑完成再确认操作的).

怀旧.png 冲印.png 铭黄.png 冲印.png 单色.png 复古.png 古画.png 热能.png

还有一些特效类型.

花瓣.png 聚光灯.png 结晶.png 万花筒.png 圆弧.png

等等,其他类型详见末尾Demo.

旋转

/**初始化*/
- (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;

效果图:


旋转.gif

画笔

/**初始化*/
- (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];

效果图:


画笔.gif

贴图

贴图与上边有些区别.贴图初始时需要设置贴图和删除键.其有另外的初始方法.(但仍包含上述方法的初始,各初始化是递进关系,并不是单一关系).

/**初始化*/
- (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];

效果图:


贴图.gif

马赛克

/**初始化*/
- (WKCImageEditorTool *)editorTool {
if (!_editorTool) {
_editorTool = [[WKCImageEditorTool alloc] initWithFrame:self.imageView.bounds sourceImage:self.imageView.image];
_editorTool.editorType = WKCImageEditorToolTypeMosaic;
_editorTool.delegate = self;
}
return _editorTool;
}

效果图:


马赛克.gif

文本

文本也要个别的初始化方法.

- (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;
}

效果图:


文本.gif

亮度、对比度、饱和度

/**初始化*/
- (WKCImageEditorTool *)editorTool {
if (!_editorTool) {
_editorTool = [[WKCImageEditorTool alloc] initWithFrame:self.imageView.bounds sourceImage:self.imageView.image];
_editorTool.editorType = WKCImageEditorToolTypeBright;
_editorTool.delegate = self;
}
return _editorTool;
}

/**调用*/
- (IBAction)valueChanged:(UISlider *)sender {
NSLog(@"值是%f",sender.value);
[self.editorTool.brightTool brightWithType:WKCBrightTypeLight value:sender.value];
[self.editorTool fire];

}

效果图:


亮度.gif

裁剪

- (WKCImageEditorTool *)editorTool {
if (!_editorTool) {
_editorTool = [[WKCImageEditorTool alloc] initWithFrame:self.imageView.bounds sourceImage:self.imageView.image];
_editorTool.editorType = WKCImageEditorToolTypeClip;
_editorTool.delegate = self;
}
return _editorTool;
}

效果图:


裁剪.gif

混合使用

当将所有工具在一个界面组合成一个编辑工具时,每次确认时,默认会更新源图,无需再特意处理.

如有bug或问题,请私信.github地址.

相关文章

网友评论

      本文标题:iOS 图片编辑

      本文链接:https://www.haomeiwen.com/subject/crnuyftx.html