wxr
2020-06-15 b8e94316e41eba72d927d5ca7d931b26139ee8ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
//  UIImageCrop.m
//  HDLWidgetLibrary
//
//  Created by HDL on 2019/10/21.
//  Copyright © 2019 JLChen. All rights reserved.
//
 
#import "UIImageCrop.h"
 
@implementation UIImageCrop
 
 
 
+(UIImage *)resizeImageWithSize:(UIImage *)img newSize:(CGSize)newSize{
    CGFloat newWidth = newSize.width;
    CGFloat newHeight = newSize.height;
    float width  = img.size.width;
    float height = img.size.height;
    if (width != newWidth || height != newHeight) {
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(newWidth, newHeight), YES, [UIScreen mainScreen].scale);
        [img drawInRect:CGRectMake(0, 0, newWidth, newHeight)];
        
        UIImage *resized = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return resized;
    }
    return img;
}
+(UIImage *)ovalClip:(UIImage *)img{
    
    CGSize size = img.size;
    UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, img.size.width, img.size.height)];
    [path addClip];
    [img drawAtPoint:CGPointZero];
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}
 
@end