Skip to content

Instantly share code, notes, and snippets.

@hulefei
Created April 15, 2016 08:37
Show Gist options
  • Save hulefei/312c34df65eb239e344547b9c3944630 to your computer and use it in GitHub Desktop.
Save hulefei/312c34df65eb239e344547b9c3944630 to your computer and use it in GitHub Desktop.
iOS压缩图片
- (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
// 设置成为当前正在使用的context
UIGraphicsBeginImageContext(size);
// 绘制改变大小的图片
[img drawInRect:CGRectMake(0, 0, size.width, size.height)];
// 从当前context中创建一个改变大小后的图片
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
// 使当前的context出堆栈
UIGraphicsEndImageContext();
// 返回新的改变大小后的图片
return scaledImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment