标签:
+(UIImage *)compressImageWith:(UIImage *)image width:(float)width height:(float)height{ float imageWidth = image.size.width; float imageHeight = image.size.height; float widthScale = imageWidth /width; float heightScale = imageHeight /height; // 创建一个bitmap的context // 并把它设置成为当前正在使用的context UIGraphicsBeginImageContext(CGSizeMake(width, height)); if (widthScale > heightScale) { [image drawInRect:CGRectMake(0, 0, imageWidth /heightScale , height)]; } else { [image drawInRect:CGRectMake(0, 0, width , imageHeight /widthScale)]; } // 从当前context中创建一个改变大小后的图片 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); [newImage retain]; // 使当前的context出堆栈 UIGraphicsEndImageContext(); return newImage; }
标签:
原文地址:http://www.cnblogs.com/sixin/p/4189318.html