图片裁剪代码

//
//  UIImage+ClicpImage.h
//  图片加水印
//
//  Created by Jason on 2019/3/13.
//  Copyright © 2019 友邦创新资讯. All rights reserved.
//

#import <UIKit/UIKit.h>


@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.
//

#import "UIImage+ClicpImage.h"

@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();
}复制代码




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值