/**
* 保持原来的长宽比,生成一个缩略图
*
* @param image 要调整的图片
* @param asize 目标尺寸
*
* @return UIImage
*/
- (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize
{
CGFloat w = image.self.size.width;
CGFloat h = image.self.size.height;
//默认图片宽度大于图片高度
CGFloat percentage = asize.width / w;
if (h < w) {
percentage = asize.height / h;
}
w = w * percentage;
h = h * percentage;
UIImage *newimage;
UIGraphicsBeginImageContext(asize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
UIRectFill(CGRectMake(0, 0, asize.width, asize.height));//clear background
[image drawInRect:CGRectMake(0, 0, w, h)];
newimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimage;
}