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