Created
March 21, 2016 02:36
-
-
Save CaliosD/c97c4167541e9c6785d9 to your computer and use it in GitHub Desktop.
图片压缩
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 *yourImage= [self imageWithImageSimple:image scaledToSize:CGSizeMake(210.0, 210.0)]; | |
- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize | |
// Create a graphics image context | |
UIGraphicsBeginImageContext(newSize); | |
// Tell the old image to draw in this newcontext, with the desired | |
// new size | |
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; | |
// Get the new image from the context | |
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); | |
// End the context | |
UIGraphicsEndImageContext(); | |
// Return the new image. | |
return newImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment