将一幅图片按着需要的尺寸进行等比的压缩和放大,最后再截取需要尺寸部分,不知道说清楚没,反正就那意思吧!
+(UIImage *)comPRessImageWith:(UIImage *)image width:(float)width height:(float)height
{floatimageWidth =image.size.width;floatimageHeight =image.size.height;floatwidthScale = imageWidth /width;floatheightScale = imageHeight /height;//创建一个bitmap的context//并把它设置成为当前正在使用的contextUIGraphicsBeginImageContext(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();returnnewImage;
}