[转]裁剪图片为正方形
Posted YouNeedCourage
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[转]裁剪图片为正方形相关的知识,希望对你有一定的参考价值。
原文:http://www.cnblogs.com/shisishao/p/6000999.html
#pragma mark 获取裁剪区域 - (CGRect)getImageRect:(UIImage *)tempImage { CGRect rect; if (tempImage.size.width > tempImage.size.height) { rect = CGRectMake((tempImage.size.width-tempImage.size.height)/2, 0, tempImage.size.height, tempImage.size.height); } else if (tempImage.size.width < tempImage.size.height) { rect = CGRectMake(0, (tempImage.size.height-tempImage.size.width)/2, tempImage.size.width, tempImage.size.width); } else { rect = CGRectMake(0, 0, tempImage.size.width, tempImage.size.width); } return rect; } #pragma mark 裁剪图片 - (UIImage *)getCropImage:(UIImage *)image andRect:(CGRect)rect { rect = CGRectMake(ceilf(rect.origin.x), ceilf(rect.origin.y), ceilf(rect.size.width), ceilf(rect.size.height)); UIGraphicsBeginImageContext(rect.size); [image drawAtPoint:CGPointMake(-rect.origin.x, -rect.origin.y)]; UIImage *cropImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return cropImage; }
以上是关于[转]裁剪图片为正方形的主要内容,如果未能解决你的问题,请参考以下文章
安卓手机怎么斜着裁剪图片,一张正方形图片我想把它斜着切掉一半