图片压缩

可以将如下两个方法写在分类中,方便不同项目的重复使用

1
2
3
4
5
6
//压缩图片质量
+ (UIImage*)reduceImage:(UIImage*)image percent:(float)percent {
NSData* imageData = UIImageJPEGRepresentation(image, percent);
UIImage* newImage = [UIImage imageWithData:imageData];
return newImage;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
//压缩图片尺寸
+ (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize {
// Create a graphics image context
UIGraphicsBeginImageContext(newSize);
// new size
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
// Get the new image from the context
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// End the context
UIGraphicsEndImageContext();
// Return the new image.
return newImage;
}