#pragma mark- 缩放图片 对大小压缩
+(UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
//设置图片尺寸
UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize));
[image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//对图片包得大小进行压缩
NSData *imageData = UIImageJPEGRepresentation(scaledImage,0.0001);
UIImage *m_selectImage = [UIImage imageWithData:imageData];
return m_selectImage;
}
//这样调用即可
UIImage* original = [info objectForKey:UIImagePickerControllerOriginalImage];
original = [HZSInstances scaleImage:original toScale:0.4];
时间: 2024-10-12 13:41:30