Created
January 5, 2015 09:09
-
-
Save maxhis/81c0fa7da2dd4bc8d1d8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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*)imageWithImage: (UIImage*) sourceImage scaledToWidth: (float) i_width | |
{ | |
float oldWidth = sourceImage.size.width; | |
float scaleFactor = i_width / oldWidth; | |
float newHeight = sourceImage.size.height * scaleFactor; | |
float newWidth = oldWidth * scaleFactor; | |
UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight)); | |
[sourceImage drawInRect:CGRectMake(0, 0, newWidth, newHeight)]; | |
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return newImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment