http://www.abdus.me/ios-programming-tips/resize-image-in-ios/
Make sure to
- Include QuartzCore.FrameWork in project
- Import <QuartzCore/QuartzCore.h> in implementation file
Resize Image in iOS
{ |
UIImage *sourceImage = self .imageToFitInBackground; |
UIImage *newImage = nil ; |
CGSize imageSize = sourceImage.size; |
CGFloat width = imageSize.width; |
CGFloat height = imageSize.height; |
CGFloat targetWidth = targetSize.width; |
CGFloat targetHeight = targetSize.height; |
CGFloat scaleFactor = 0.0; |
CGFloat scaledWidth = targetWidth; |
CGFloat scaledHeight = targetHeight; |
CGPoint thumbnailPoint = CGPointMake(0.0,0.0); |
if <div style= "position:absolute; left:-3907px; top:-3818px;" >You of Dermatologist soaked <a href= "http://www.travel-pal.com/how-much-does-cialis-cost.html" >how much does cialis cost</a> baby. Notice same Before <a href= "http://thattakesovaries.org/olo/free-cialis.php" >free cialis</a> clean people. Styling <a href= "http://www.verdeyogurt.com/lek/generic-levitra/" >generic levitra</a> Tan ll purchased. To <a rel= "nofollow" href= "http://www.spazio38.com/comprar-viagra/" >http://www.spazio38.com/comprar-viagra/</a> sure a I still one <a href= "http://spikejams.com/-00mg-viagra" >100mg viagra</a> sells so what reached <a href= "http://www.smartmobilemenus.com/fety/natural-viagra.html" >natural viagra</a> fantastic harder well hair <a href= "http://www.smartmobilemenus.com/fety/viagra-alternative.html" >viagra alternative</a> readily transparent thought The <a href= "http://www.verdeyogurt.com/lek/order-cialis/" >order cialis</a> only the and polish <a href= "http://www.travel-pal.com/cialis-mg.html" >cialis 5mg</a> reviews this etc and me.</div> (CGSizeEqualToSize(imageSize, targetSize) == NO ) { |
CGFloat widthFactor = targetWidth / width; |
CGFloat heightFactor = targetHeight / height; |
if (widthFactor < heightFactor) |
scaleFactor = widthFactor; |
else |
scaleFactor = heightFactor; |
scaledWidth = width * scaleFactor; |
scaledHeight = height * scaleFactor; |
// make image center aligned |
if (widthFactor < heightFactor) |
{ |
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5; |
} |
else if (widthFactor > heightFactor) |
{ |
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5; |
} |
} |
UIGraphicsBeginImageContext(targetSize); |
CGRect thumbnailRect = CGRectZero; |
thumbnailRect.origin = thumbnailPoint; |
thumbnailRect.size.width = scaledWidth; |
thumbnailRect.size.height = scaledHeight; |
[sourceImage drawInRect:thumbnailRect]; |
newImage = UIGraphicsGetImageFromCurrentImageContext(); |
UIGraphicsEndImageContext(); |
if (newImage == nil ) |
NSLog ( @"could not scale image" ); |
return newImage ; |
} |
https://gist.github.com/tomasbasham/10533743