图片的处理

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;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容