//压缩图片 解决图片过多 内存过大
+ (UIImage *)newImageWithImage:(UIImage *)image{
//实现等比例缩放
float hfactor = image.size.width/KWidth;
float vfactor = image.size.height/KHeight;
float factor = fmaxf(hfactor, vfactor);
//画布大小
CGFloat newWidth = image.size.width/factor;
CGFloat newHeight = image.size.height/factor;
CGSize newSize = CGSizeMake(newWidth, newHeight);
UIGraphicsBeginImageContext(newSize);
[image drawInRect:SetFrame(0, 0, newWidth, newHeight)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//图像压缩
NSData *newImageData = UIImageJPEGRepresentation(newImage, 0.5);
return [UIImage imageWithData:newImageData];
}