Demo下载地址:
类似于呱呱卡效果,手指划过的路线可以刮出痕迹。
用于取出部分图片(截图),如截取出图片中带文字的区域部分。




#import "HKCropView.h" #import "HKLineView.h"
@property (nonatomic, strong) HKCropView *cropView;
@property (nonatomic, strong) HKLineView *lineView;
// 画笔的属性在这里修改 - (HKLineView *)lineView { if (!_lineView) { _lineView = [[HKLineView alloc] init]; _lineView.backgroundColor = [UIColor blackColor]; _lineView.alpha = 0.5; _lineView.delegate = self; _lineView.currentLineColor = [UIColor whiteColor]; _lineView.currentLineWidth = 20.0; } return _lineView; }
<HKScreenShotImageViewRectDelegate>
使用Demo中ViewController.m中的"fixOrientation:"方法修复。
// 修复照片的方向问题 - (UIImage *)fixOrientation:(UIImage *)aImage
// 在原始图片上蒙上一层半透黑底背景 // originalImageView为显示选取image的imageView self.lineView.frame = self.originalImageView.frame; [self.view addSubview:self.lineView];
// 代理回调手指划出图片的区域rect - (void)getScreenShotImageViewRect:(CGRect)rect { // 获取到需要截取图片的区域rect }
- (UIImage *)clipWithImageRect:(CGRect)clipRect clipImage:(UIImageView *)orgiImageView {
if (!_cropView) {
// 初始化
_cropView = [[HKCropView alloc] initWithImageView:orgiImageView];
}
UIImage *newImage = [_cropView getClipImageRect:clipRect];
[_cropView removeFromSuperview];
_cropView = nil;
return newImage;
}
/** 初始化剪切视图 @param imageView 原始图片imageView @return self */ - (id)initWithImageView:(UIImageView *)imageView; /** 获取剪切图片 传入一个rect @param newRect 需要截图的区域rect @return 截取出来的图片image */ - (UIImage *)getClipImageRect:(CGRect)newRect;
@property (nonatomic,assign) float lineWidth;//线宽 @property (nonatomic,strong) UIColor *lineColor;//线颜色 @property (nonatomic,strong) NSMutableArray *linePointsMArr;//线点数组
/** 清空所有的线 */ -(void)cleanAllLine; /** 撤销上一条线 */ -(void)cleanBeforeLine;
??注意:
本demo为了简洁明了,直接选取的是正方形的图片。如果选择非正方形图片会导致变形,这样截图区域会不准确。
正确做法:应该在展示image时,根据image具体的比例调整“orgiImageView”的frame,这样截取出来的图片才是正确的。