//
// UIImage+ClicpImage.h
// 图片加水印
//
// Created by Jason on 2019/3/13.
// Copyright © 2019 友邦创新资讯. All rights reserved.
//
@interface UIImage (ClicpImage)
+ (UIImage *)imageWithBorderWidth:(CGFloat)border color:(UIColor *)color image:(UIImage *)image;
@end
//
// UIImage+ClicpImage.m
// 图片加水印
//
// Created by Jason on 2019/3/13.
// Copyright © 2019 友邦创新资讯. All rights reserved.
//
@implementation UIImage (ClicpImage)
+ (UIImage *)imageWithBorderWidth:(CGFloat)border color:(UIColor *)color image:(UIImage *)image {
CGSize size = CGSizeMake(image.size.width + 2 * border, image.size.height + 2 * border);
UIGraphicsBeginImageContext(size);
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, size.width, size.height)];
[[UIColor redColor] set];
[path fill];
//设置小圆
UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(border, border, image.size.width, image.size.height)];
[clipPath addClip];//设置裁剪区域
[image drawAtPoint:CGPointMake(border, border)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end复制代码
截屏代码
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UIGraphicsBeginImageContext(self.view.bounds.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
NSData *data = UIImagePNGRepresentation(image);
[data writeToFile:@"/Users/admin/Desktop/autoScrren.png" atomically:YES];
UIGraphicsEndImageContext();
}复制代码