您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页图片的处理

图片的处理

来源:二三娱乐

UIImage *image =[UIImage imageNamed:@"tt"];

UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);

UIBezierPath *path =[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];

[path addClip];

[image drawAtPoint:CGPointZero];

UIImage *clipImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

_imageView =[[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-50, self.view.frame.size.height/2-50, 100, 100)];

_imageView.image=clipImage;

[self.view addSubview:_imageView]

二 

-(UIImage*)cutImg:(UIImage*)image withSize:(CGSize)asize{

UIImage *newimage;

if (nil == image) {

newimage = nil;

} else {

CGSize oldsize = image.size;

CGRect rect;

if ((asize.width / asize.height) > (oldsize.width / oldsize.height)) {

rect.size.width    = asize.width;

rect.size.height    = (asize.width * oldsize.height) / oldsize.width;

rect.origin.x      = 0;

rect.origin.y      = (asize.height - rect.size.height) / 2;

} else {

rect.size.width    = (asize.height * oldsize.width) / oldsize.height;

rect.size.height    = asize.height;

rect.origin.x      = (asize.width - rect.size.width) / 2;

rect.origin.y      = 0;

}

UIGraphicsBeginImageContext(asize);

CGContextRef context    = UIGraphicsGetCurrentContext();

CGContextClipToRect(context, CGRectMake(0, 0, asize.width, asize.height));

CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);

UIRectFill(CGRectMake(0, 0, asize.width, asize.height));

[image drawInRect:rect];

newimage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

}

return newimage;

}

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务