Created
April 15, 2016 08:37
-
-
Save hulefei/312c34df65eb239e344547b9c3944630 to your computer and use it in GitHub Desktop.
iOS压缩图片
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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