// 添加 UIImage 的分类 ResizeUIImage
@implementation UIImage (ResizeUIImage)
/**
重绘图片大小
@param size 要得到的图片的尺寸大小
@return 得到的指定尺寸大小的图片
*/
- (UIImage *)resizeImageToSize:(CGSize)size {
// change from UIGraphicsBeginImageContext(size) to suit scale > 1
UIGraphicsBeginImageContextWithOptions(size, false, 0);
[self drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end
// 重新设置图片的大小
image = [image resizeImageToSize:CGSizeMake(100, 200)];